murdocsvan Posted June 26, 2010 Share Posted June 26, 2010 This is my code: //Manage image upload and put into directory: if(($_FILES["image"]["type"] == "image/jpg") || ($_FILES["file"]["type"] == "image/jpeg")) { if ($_FILES["image"]["error"] > 0) { echo "Return Code: " . $_FILES["image"]["error"] . "<br />"; } else { if(file_exists("../images/" . $_FILES['image']['name'])) { echo 'Error: File already exists'; } else { move_uploaded_file($_FILES["image"]["tmp_name"], "../images/" . $_FILES["image"]["name"]); echo "Stored in: " . "../images/" . $_FILES["image"]["name"]; } } } else { echo 'Invalid file type'; } When i upload a file using a form, that's the right file type, it always returns invalid file type. I think the problem is with; if(($_FILES["image"]["type"] == "image/jpg") || ($_FILES["file"]["type"] == "image/jpeg")) Quote Link to comment https://forums.phpfreaks.com/topic/205932-problem-determining-file-type-in-_file/ Share on other sites More sharing options...
premiso Posted June 26, 2010 Share Posted June 26, 2010 Well part of the problem could be that you are using "file" in the second part of the if / or statement instead of "image". To make sure the value is what it should be echo it out for debugging, as PHP is case sensitive and that could be a potential issue too. Quote Link to comment https://forums.phpfreaks.com/topic/205932-problem-determining-file-type-in-_file/#findComment-1077603 Share on other sites More sharing options...
murdocsvan Posted June 26, 2010 Author Share Posted June 26, 2010 Hey thanks that helped But now i think there's a problem with my hosting. i got the following error: Warning: move_uploaded_file(214047) [function.move-uploaded-file]: failed to open stream: Permission denied in [LOCATION OF MY SCRIPT ON THE SERVER] on line 34 Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'D:\Temp\php\php7C77.tmp' to '214047' in [LOCATION OF MY SCRIPT ON THE SERVER] on line 34 I'm guessing this has something to do with my hosting? I'm calling them atm to see if they can resolve it, because it doesn't look like an error with the PHP to me. Quote Link to comment https://forums.phpfreaks.com/topic/205932-problem-determining-file-type-in-_file/#findComment-1077614 Share on other sites More sharing options...
murdocsvan Posted June 26, 2010 Author Share Posted June 26, 2010 Well it turned out Godaddy don't allow anyone to access the tmp PHP directory, but thanks for your help anyway. Quote Link to comment https://forums.phpfreaks.com/topic/205932-problem-determining-file-type-in-_file/#findComment-1077618 Share on other sites More sharing options...
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.