jwilh Posted November 4, 2006 Share Posted November 4, 2006 I am following a tutorial create an uploader for my site but it is not working for some strange reason , it keeps saying file is invalid when i try to upload a small pic, and then when it does go through i cannot find it on my server.Here is the code for it:[code]<?phpif ($_FILES["file"]["error"] > 0) { echo "Error: " . $_FILES["file"]["error"] . "<br />"; }else { echo "Upload: " . $_FILES["file"]["name"] . "<br />"; echo "Type: " . $_FILES["file"]["type"] . "<br />"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />"; echo "Stored in: " . $_FILES["file"]["tmp_name"]; }?><?phpif (($_FILES["file"]["type"] == "image/gif")|| ($_FILES["file"]["type"] == "image/jpeg")&& ($_FILES["file"]["size"] < 30000)) { if ($_FILES["file"]["error"] > 0) { echo "Error: " . $_FILES["file"]["error"] . "<br />"; } else { echo "Upload: " . $_FILES["file"]["name"] . "<br />"; echo "Type: " . $_FILES["file"]["type"] . "<br />"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />"; echo "Stored in: " . $_FILES["file"]["tmp_name"]; } }else { echo "Invalid file"; }?><?phpif (($_FILES["file"]["type"] == "image/gif")|| ($_FILES["file"]["type"] == "image/jpeg")&& ($_FILES["file"]["size"] < 30000)) { if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; } else { echo "Upload: " . $_FILES["file"]["name"] . "<br />"; echo "Type: " . $_FILES["file"]["type"] . "<br />"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />"; echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />"; if (file_exists("upload/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]); echo "Stored in: " . "upload/" . $_FILES["file"]["name"]; } } }else { echo "Invalid file"; }?>[/code] Link to comment https://forums.phpfreaks.com/topic/26109-new-uploader-help/ Share on other sites More sharing options...
ToonMariner Posted November 4, 2006 Share Posted November 4, 2006 If that is true then the if statement is not satisfied with the file that is being offered it.Check what is echoed out and compare it to your requirements. Link to comment https://forums.phpfreaks.com/topic/26109-new-uploader-help/#findComment-119388 Share on other sites More sharing options...
jwilh Posted November 4, 2006 Author Share Posted November 4, 2006 I keep the files under 30kb and I keep the ext. either gif or jpg and they still wont work. So I dont have a clue, I am a beginner so I must be missing something! ??? Link to comment https://forums.phpfreaks.com/topic/26109-new-uploader-help/#findComment-119390 Share on other sites More sharing options...
ToonMariner Posted November 4, 2006 Share Posted November 4, 2006 try altering your if to this..if (($_FILES["file"]["type"] == "image/gif"|| $_FILES["file"]["type"] == "image/jpeg")&& $_FILES["file"]["size"] < 30000)Also make sure that your file input is called 'file' (sometimes the most obvious thing is overlooked ;)) Link to comment https://forums.phpfreaks.com/topic/26109-new-uploader-help/#findComment-119392 Share on other sites More sharing options...
jwilh Posted November 4, 2006 Author Share Posted November 4, 2006 Im sorry what do u mean by my file input? Link to comment https://forums.phpfreaks.com/topic/26109-new-uploader-help/#findComment-119393 Share on other sites More sharing options...
jwilh Posted November 4, 2006 Author Share Posted November 4, 2006 Nm i figured that out and part of it worked, but then i got this.[code]Warning: move_uploaded_file(upload/s###.jpg): failed to open stream: No such file or directory in /home/www/#######.com/php/upload_file.php on line 63Warning: move_uploaded_file(): Unable to move '/tmp/phpQft5yL' to 'upload/###.jpg' in /home/www/########/php/upload_file.php on line 63Stored in: upload/###.jpg[/code] Link to comment https://forums.phpfreaks.com/topic/26109-new-uploader-help/#findComment-119398 Share on other sites More sharing options...
jwilh Posted November 4, 2006 Author Share Posted November 4, 2006 Nevermind on that one as well I Figured it out with a little common since lol. Thank you for your help Ive been on this for over a day now so it really helped me out! :) Link to comment https://forums.phpfreaks.com/topic/26109-new-uploader-help/#findComment-119399 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.