PHP image upload .....HELP

They have: 105 posts

Joined: Jan 2002

I'm not sure what it is I'm doing wrong and please excuse the unoptimized code.

Here's the problem:
I'm trying to 1. upload and image
2. store the image name in the database according to the product id it is associated with

I have the name storage under control, but the image itself will not upload. It has the extension of .jpg, but when I try to print out the filetype

echo "Filetype: (".$_FILES['imagefile']['name'].")";

The result is blank. I know the image must have a filetype, right?

The complete code is below.

-------------------------------------------------------------
$imagetypes = Array ("image/gif", "image/pjpeg", "image/jpeg", "image/djpeg");

if (in_array($_FILES['imagefile']['type'], $imagetypes))
{ upload }

else {
echo "Filetype: (".$_FILES['imagefile']['name'].")";
}

The upload code isn't really necessary,since it never gets to taht point Smiling

CPRhosting.com - CPR Hosting...Giving life to the web
Custom-made Hosting Plans starting at $2

He has: 1,016 posts

Joined: May 2002

Why don't you have your upload code posted? The code you have posted will post the filetype ONLY IF the upload fails. So if the filetype is not printed to the browser, it must mean that the upload if successful, but perhaps your script doesn't handle the uploaded file correctly.

They have: 105 posts

Joined: Jan 2002

well, everytime I attempt to upload the jpeg, it goes straight to the "Incorrect Filetype" portion of the code. I assumed that the upload portion isn't even being run.

CPRhosting.com - CPR Hosting...Giving life to the web
Custom-made Hosting Plans starting at $2

He has: 1,016 posts

Joined: May 2002

Can you post your HTML to code?

They have: 105 posts

Joined: Jan 2002

<?php
echo\"<form method=post action=$PHP_SELF><center>

<table>
<tr><td>Image 1 <input type=\\"
file\\" name=\\"imagefile1\\"> </td></tr>
<tr><td>Image 2 <input type=\\"
file\\" name=\\"imagefile2\\"> </td></tr>
</table>

</form>\";
?>

CPRhosting.com - CPR Hosting...Giving life to the web
Custom-made Hosting Plans starting at $2

He has: 1,016 posts

Joined: May 2002

1. You need to add enctype="multipart/form-data" to your tag...

2. In your HTML you have the 2 file fields named "imagefile1" and "imagefile2" but in your PHP code you're trying to get the filetype and filename of "imagefile" (without the 1 or 2 at the end).

They have: 105 posts

Joined: Jan 2002

worked like a charm. THANKS~

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.