rkrathor Posted April 25, 2014 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 Link to comment Share on other sites More sharing options...
thescientist Posted April 25, 2014 Share Posted April 25, 2014 where's your markup? Link to comment Share on other sites More sharing options...
justsomeguy Posted April 25, 2014 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. Link to comment Share on other sites More sharing options...
rkrathor Posted April 26, 2014 Author Share Posted April 26, 2014 where's your markup? I didn't get what you asking for? Thanks Link to comment Share on other sites More sharing options...
rkrathor Posted April 26, 2014 Author 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 Link to comment Share on other sites More sharing options...
thescientist Posted April 28, 2014 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. Link to comment Share on other sites More sharing options...
justsomeguy Posted April 29, 2014 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. Link to comment Share on other sites More sharing options...
rkrathor Posted May 3, 2014 Author 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 Link to comment Share on other sites More sharing options...
thescientist Posted May 5, 2014 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. Link to comment Share on other sites More sharing options...
BigShieldsy Posted May 5, 2014 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 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now