Forum Moderators: coopster

Message Too Old, No Replies

Simple Uploading Image Script

Where is my typo?

         

Jeremy_H

4:47 pm on Jun 30, 2006 (gmt 0)

10+ Year Member



Hello,

I'm trying to allow my visitors to upload an image onto the server using PHP.

I've followed some tutorials, but I haven't been able to get it to work.

I was hoping somebody could look at my code and tell me if I have a typo or something.

On the form page:

<form method="post" action="/upload.php" enctype="multipart/form-data">
<input type="file" name="o12" accept="image/jpeg">
</form>

Then on the PHP page:

if($o12['type']=="image/jpeg"){
copy($o12['tmp_name'],"/images/".$o12['name']);
}

Thanks.

whoisgregg

5:25 pm on Jun 30, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What error do you receive?

Jeremy_H

5:55 pm on Jun 30, 2006 (gmt 0)

10+ Year Member



When I try to upload an image using the form nothing happens. There isn't an error message or anything, just no image has been loaded.

adni18

7:49 pm on Jun 30, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Do you have REGISTER_GLOBALS on?

whoisgregg

8:24 pm on Jun 30, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Add these two lines to the beginning of your script, run the script, then report back with the error. :)

ini_set('error_reporting', E_ALL);
ini_set('display_errors', "On");

the_nerd

9:39 pm on Jun 30, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Maybe you want to try this:

if ($_FILES ['o12']['error'] == 0) {
Move_Uploaded_File ($_FILES['o12']['tmp_name'], "destinationfilename");
}
else {
echo "error uploading files - further testing needed";
}

The problem could also be your type-checking. AFAIK the file-type is a numerical value in php.