rkrathor 1 Posted April 25, 2014 Report Share Posted April 25, 2014 Hi, I am using this code from w3schools but it giving me error (Invalid file ). This is the code <?php$allowedExts = array("gif", "jpeg", "jpg", "png");$temp = explode(".", $_FILES["file"]["name"]);$extension = end($temp);if ((($_FILES["file"]["type"] == "image/gif")|| ($_FILES["file"]["type"] == "image/jpeg")|| ($_FILES["file"]["type"] == "image/jpg")|| ($_FILES["file"]["type"] == "image/pjpeg")|| ($_FILES["file"]["type"] == "image/x-png")|| ($_FILES["file"]["type"] == "image/png"))&& ($_FILES["file"]["size"] < 20000)// if i change this by ">" then it taking every size&& in_array($extension, $allowedExts)) { 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("rajesh/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "rajesh/" . $_FILES["file"]["name"]); echo "Stored in: " . "rajesh/" . $_FILES["file"]["name"]; } }} else { echo "Invalid file";}?> Can you please check and give the correct code? Thanks Quote Link to post Share on other sites
thescientist 231 Posted April 25, 2014 Report Share Posted April 25, 2014 where's your markup? Quote Link to post Share on other sites
justsomeguy 1,135 Posted April 25, 2014 Report Share Posted April 25, 2014 If it says invalid file then that if statement is failing. So the mime type is not in the list, or the size is too big, or it has the wrong extension. Quote Link to post Share on other sites
rkrathor 1 Posted April 26, 2014 Author Report Share Posted April 26, 2014 where's your markup? I didn't get what you asking for? Thanks Quote Link to post Share on other sites
rkrathor 1 Posted April 26, 2014 Author Report Share Posted April 26, 2014 If it says invalid file then that if statement is failing. So the mime type is not in the list, or the size is too big, or it has the wrong extension. Hi, that i know to but what i want to say, the whole code said that if the size go beyond 20000 then it will show invalid file but in this case every time it showing invalid file and if change it to > then its working fine but it taking every size either less then or more than 20000. Thanks Quote Link to post Share on other sites
thescientist 231 Posted April 28, 2014 Report Share Posted April 28, 2014 I didn't get what you asking for? Thanks The markup is the HTML. I was hoping to see the form that you're (presumably) using to submit the file upload with. Quote Link to post Share on other sites
justsomeguy 1,135 Posted April 29, 2014 Report Share Posted April 29, 2014 the whole code said that if the size go beyond 20000 then it will show invalid file but in this case every time it showing invalid fileThe size is not the only reason why it would show invalid file. Quote Link to post Share on other sites
rkrathor 1 Posted May 3, 2014 Author Report Share Posted May 3, 2014 The size is not the only reason why it would show invalid file. Hi, Then what could be other reason. can you please elaborate little bit. thanks Quote Link to post Share on other sites
thescientist 231 Posted May 5, 2014 Report Share Posted May 5, 2014 all these conditions are part of the same if block, who's else block outputs Invalid file if ((($_FILES["file"]["type"] == "image/gif")|| ($_FILES["file"]["type"] == "image/jpeg")|| ($_FILES["file"]["type"] == "image/jpg")|| ($_FILES["file"]["type"] == "image/pjpeg")|| ($_FILES["file"]["type"] == "image/x-png")|| ($_FILES["file"]["type"] == "image/png"))&& ($_FILES["file"]["size"] < 20000)// if i change this by ">" then it taking every size&& in_array($extension, $allowedExts)) { You need to debug all parts of your code so you can actually tell what values are what, and be able to follow what your code doing. Quote Link to post Share on other sites
BigShieldsy 0 Posted May 5, 2014 Report Share Posted May 5, 2014 Hi i started with this code and had the same issue with it i have since manage to update the code to allow the file to uploaded to the server's tmp folder (however this is now where i am stuck as i am not allowed to move the file fue to hosting security reason and i am in the process of trying to find out how to change the server tmp location to a location with in my own account folder..Here is a link to the topic i had created.. in here you will be able to see the code as well.. Hope its helpshttp://w3schools.invisionzone.com/index.php?showtopic=50284 Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.