Uploading Files with PHP
Tuesday May 23, 2006
You're in a hurry to show a friend a photo you just took, and instead of opening up your FTP program and uploading it you just whip over to ImageShack and upload it there.
You can actually upload files from your browser to your server like this using a very small PHP script. The files are then saved to whatever folder you specify on your server. Remember if you plan to utilize this and give access to someone other than yourself, make sure you write in some security measures to keep people from uploading malicious code.
You can actually upload files from your browser to your server like this using a very small PHP script. The files are then saved to whatever folder you specify on your server. Remember if you plan to utilize this and give access to someone other than yourself, make sure you write in some security measures to keep people from uploading malicious code.


Comments
I am using your script exactly as is - one HTML file and one PHP file, the folder has been created for the php, etc. but I just cannot get this to work - has the script been updated or anything?
bad article. (!($filetype == “image/gif”)) ??? why not just $filetype != “image/gif” also, that is a very bad, yes BAD way to check if a file is of a certain type. imagine a rigged http request. oh yes it can be done very easily
The PHP line reporting back that the file uploaded… “The file xxxx has been uploaded” has a small error that prevents it from reporting the file name. the line:
echo “The file “.basename( $_FILES[’uploadedfile‘][’name’]). ” has been uploaded”;
should be:
echo “The file “.basename( $_FILES[’uploaded‘][’name’]). ” has been uploaded”;
to correctly report the file name.
I WANT TO UPLOAD A PIC TO A WEB PAGE AND TRIED THIS PHP BUT I MUST HAVE DONE SOMETHING WRONG. CAN ANYONE HELP??
SLIMSAM46@YAHOO.COM
I can not get this code to work, i COPY AND PASTED EVERYTHING and created a /upload folder on the ftp in the correct directory and it gives me:
Sorry, there was a problem uploading your file.
please help!
jdbeitz@gmail.com
Did you CHMOD the directory correctly? That is an important step in the script.
i’ve been try to CHMOD the directory.. but still can not work… why?
pls help
The CHMOD worked for me! However the upload will not allow one file over 3 MB to upload. What is causing this file limitation?
Any ideas will be great!
dana.mathews@comcast.net
Not sure what is going on. The Global_register variable on the server is set to off so I need to get the $_FILES information from a $_POST apparently. I can’t seem to get it to work properly.
I’m confused… $uploaded_size and $uploaded_type are never set. They of course evaluate out to nothing at all and that part of the code doesn’t do anything. The $_FILES[’uploaded’][type] and $_FILES[’uploaded’][’size’] do contain this information.
i understood the whole code given here but i can’t find any sample i.e example.
hi, it worked but need improvments, first i think people need to change cmhd, (i didn’t change it i simly used another website, because some wont allow any way), the other thing as (Anon) saied in the posts, there should be only a single
=
not ( not two of them)
==
but they wont change anything !! because you change all of the variables and still be able to upload .php or (if you changed the size) upload more that you limited ?!
also all the these messages:
Your file is too large.
No PHP files
The file has been uploaded
what is left !!!!!! heheheh
also ( not a problem but a request ) there sould be a message saying :
“you will be redirected to the main page after few seconds. ”
because the only way to leave the page is to hit the Back button.
please if you found a way to fix the problems, and to say the specific resones for the problems,
please email me at :
riffaey@w.cn
in the previouse comment at the end i ment that someone should mention the html code that going to redirect the visitor back PLUS saying that it will.