开发者

why does my form only accept .jpeg files

I made this form:

   <form enctype="multipart/form-data" action="php/handler.php" method="post" name="uploaderform">
    <table>
    <tr><td align="right">File:</td><td><input type="hidden" name="MAX_FILE_SIZE" value="30000"/><input type="file" name="filetoup" id="zzz"/></td></tr>
    <tr><td align="right">Folder:</td><td><select id="category" name="category"><option value="foo/">some</option><option value="poo/">some2</option></select></td></tr>
 开发者_高级运维   <tr><td></td><td><input type="submit" value="Upload" /></td></tr>
    </table>
  </form>

and this PHP script:

if((exif_imagetype($_FILES["filetoup"]["tmp_name"])==IMAGETYPE_GIF)
||(exif_imagetype($_FILES["filetoup"]["tmp_name"])==IMAGETYPE_JPEG)
||(exif_imagetype($_FILES["filetoup"]["tmp_name"])==IMAGETYPE_PNG)
&&($_FILES["filetoup"]["size"]<2000000)){
if($_FILES["filetoup"]["error"]>0)
    echo $_FILES["filetoup"]["error"];
else {

    if(isset($_FILES["filetoup"]["name"]))
        $target_path=$folder . basename($_FILES["filetoup"]["name"]);
    else
        echo "Choose a file";

    if(move_uploaded_file($_FILES["filetoup"]["tmp_name"],$target_path))
        echo $_FILES["filetoup"]["name"] . "uploaded";
    else
        echo "Either you fucked up or I did";
    }
 }else{
echo "read whats under the form";
 }

and I can only upload .jpeg files, .gif and .png are not accepted and I get this error:

Warning: exif_imagetype() [function.exif-imagetype]: Filename cannot be empty in      C:\xampp\htdocs\atthepc\php\handler.php on line 7

I think that it's something from my form, because I can upload .jpeg without any errors but .gif and .png not. If I'm not right, what then is causing this? And is there a solution or am I doing everything wrong?

And finally, are .jpg recognized as .jpeg's?

/edit

i dont think i explained myself correctly, if i try to upload a jpeg file, it works fine but if i try any other file type it gives me Filename cannot be empty in , so my form doesnt want to accept the gif and send it through post, its like the post is empty. why is thsi happening?

//edit and yes that is it, i tried this

$something=$_FILES["filetoup"]["tmp_name"];
var_dump($something);

and it gives me string(0) "" . the form doesnt want to accept it but why? i did not put any restriction in the form.

///edit

i found my problem, it was not accepting any other file type because what i was trying to upload was too big(animated gif) and the max_file_size was too little.


maybe try comparing type with an IF statement instead of tmp_name with exif_imagetype? $_FILES["filetoup"]["type"])==IMAGETYPE_GIF

Also, re JPEG, w3schools.com mentions that:"Note: For IE to recognize jpg files the type must be pjpeg, for FireFox it must be jpeg." so maybe that's something to look into


use a switch case insted of all the if's and set the $target_path in the case for each jpeg, png and gif, if they needs to be in different folders.. and make the default as an error if tmp image file aint allowed..

just one way to do it, hope it helps

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜