0

ok, so I made this and this works just fine and well:

$file_name = $HTTP_POST_FILES['ufile1']['name'];
$file_name_for_db = ($HTTP_POST_FILES['ufile1']['name']);
$new_file_name = $id."_pic1_".$file_name;
$path = "../users/".$username_session."/photos/".$new_file_name;

if($ufile !=none)
{
    copy($HTTP_POST_FILES['ufile1']['tmp_name'], $path);
    $path_of_pic = "../users/".$username_session."/photos/".$id."_pic1_".$file_name_for_db;
    mysql_query("UPDATE pictures SET pic_1 = '".$path_of_pic."' WHERE id = '$id'");
    header("location:../upload/");
}
else
{
    echo "Error";
}

Now what I've been trying to do is add restrictions.

I've looked through many restriction tutorials, they don't work, always returns error no matter what.

I just want to restric from users uploading anything other than pictures (.png, .jpg, .jpeg, .gif, .bmp) and no more than 5mb

I can do this in HTML, but you can easily get past that. I'm pretty new to programming, so I apologize if the way I write my codes is poor and bulky.

This site has helped me a whole bunch a few times! You guys are awesome! thanks in advance.

2 Answers 2

2

this link will help you to restrict images other then .jpg, .jpeg, and so on also the maximum upload size, and if you want to resize the image then also follow the tutorial : http://www.9lessons.info/2009/03/upload-and-resize-image-with-php.html

Sign up to request clarification or add additional context in comments.

Comments

0
if( !@imagecreatefromstring(file_get_contents($path))) {
    // (most likely) not an image
}

And:

if( filesize($path) > 5<<20) {
    // image is bigger than 5MB
}

1 Comment

if( !@imagecreatefromstring(file_get_contents($path))) { // (most likely) not an image echo error not an image; } else { upload image } is this the way that would work or vise versa?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.