Uploading Images in PHP
After dabbling in PHP for some time, and writing an image upload script about 8 months ago, I would like to post it here, with a short tutorial. I have recently reused the script and a friend of mine asked how he would go about doing such a thing. My upload script, to begin, is a function in PHP that returns the path of the image file, which I then add to a database.
The first thing you must do is set the form up correctly. along with the form name and method (for this, method="post"), you have to specify that you are uploading more than text. Simply add enctype="multipart/form-data" in the form tag. Second, you have to set the permissions on your server to allow uploads. You have to set the Permissions to “777” or Read, Write, Execute for Owner, Group and Public (or World).

Now onto the function. While processing the form, all you do is add something like $image= upload_pic($picName);. This calls the function upload_pic(), passing the argument $picName. The following is an image with well documented code explaining what is going on. For some reason, WordPress doesn’t like it when I code right in the post. At the bottom of the post is a .txt file with all of the code in this post.

Here is the .txt file with all of the code shown above. If you have any questions, or feel I missed something, be sure to comment on it! Later.
