Question:
Help! Php file upload form, images only 55mb max needed?
Veyrong
2012-06-16 11:47:37 UTC
I need help with a file upload form.
Here the code I have from an Article:


$target = "upload/";
$target = $target . basename ( $_FILES['uploaded'] ['name']) ;
$ok=1;

//This is our size condition
if ($uploaded_size > 57671680)
{
echo "Your file is too large.
";
$ok=0;
}

//This is our limit file type condition
if ($uploaded_type =="text/php")
{
echo "No PHP files
";
$ok=0;
}

//Here we check that $ok was not set to 0 by an error
if ($ok==0)
{
Echo "Sorry your file was not uploaded";
}

//If everything is ok we try to upload it
else
{
if(move_uploaded_file ($_FILES['uploaded'] ['tmp_name'], $target))
{
echo "The file ". basename ( $_FILES['uploadedfile'] ['name']). " has been uploaded";
}
else
{
echo "Sorry, there was a problem uploading your file.";
}
}


and it works but I need it to accept only image files type (jpeg, gif, png, psd, ai)
with a Maximum file size of 55MB.
and of course with the minimum bugs possible.
what do you recommend me?
Three answers:
anonymous
2012-06-16 12:00:13 UTC
You need to use a strpos() or similar against the file names to check for .jpg, jpeg, gif, png or whatever types. Be aware this does NOT protect your system, or those of your visitors. Anyone can write a hacking script, especially for a php site, and then rename it as one of these types. Your uploader would still accept them, so you also need to run checks on them for mime types. This reads the first few bytes of each file and compares them to the required types, then you need to dump any which do not comply. There is a ot nvolved in that you will need to read tutorials and manuals for all the details.
anonymous
2012-06-16 18:55:51 UTC
check out http://www.hotscripts.com/forums/php/7986-image-upload-file-type-check-file-size-check.html
anonymous
2012-06-16 18:58:53 UTC
just make some "IF statements asking if file type is ==


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...