Jump to content

Upload Image Question


ayok

Recommended Posts

Hi,

Now I'm trying to create a form to a database which contain image. So besides submitting some data, it also upload an image to a folder. But everytime I upload the image, the script acknowledge it as a non image file. Here are part my codes:

 

upload_form.php:

<?php
<tr><td>Upload Image:</td> <td>
<input type=file name=fupload></td></tr></table>
<INPUT TYPE=SUBMIT VALUE=Go>
</FORM>

 

input image.php

<?php
$direktori_file = "products/pics/$fupload_name";
if($fupload_type != "image/gif" AND $fupload_type != "image/jpeg" AND$fupload_type != "image/pjpeg" AND $fupload_type != "image/png"){
	echo "The type of file <b>$fupload_name</b> is $fupload_type<br>";
	echo "The file must be image file<br>";
	echo "<a href=add.php>Upload again!</a>";
}
elseif (!move_uploaded_file($fupload, "$direktori_file")){
	echo "The upload is failed!";
}

everytime I submit the pic, i've got this kind of message:

The type of file pic01.gif is image/gif

The file must be image file

Upload again!

 

Why the script doesn't recognize my gif/jpeg files?

 

FYI, I still test this on localhost.

 

thanks,

ayok

Link to comment
Share on other sites

Strange..

I changed the AND's into OR's as you adviced, but it didn't affect, so I changed back to AND's. Now I've got different result.

 

It's my form.php, btw:

<FORM><tr><td>Content:</td> <td><INPUT NAME=Content type=text size=10 maxlength="2"></td></tr>
<tr><td>Price:</td> <td>EUR <input NAME=Price type=text size=10 maxlength="10">
(please use .00 as decimal)</td></tr>
<tr><td>Upload Image:</td> <td>
<input type=file name=fupload></td></tr></table>
<INPUT TYPE=SUBMIT VALUE=Go>
</FORM>

Link to comment
Share on other sites

form correct format

<!-- The data encoding type, enctype, MUST be specified as below -->
<form enctype="multipart/form-data" action="__URL__" method="POST">
    <!-- MAX_FILE_SIZE must precede the file input field -->
    <input type="hidden" name="MAX_FILE_SIZE" value="30000" />
    <!-- Name of input element determines name in $_FILES array -->
    Send this file: <input name="userfile" type="file" />
    <input type="submit" value="Send File" />
</form>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.