jesi Posted November 30, 2006 Share Posted November 30, 2006 [code=php:0]<?php$target_path = "test/";$target_path = $target_path . basename($_FILES["file"]["name"]);if ((move_uploaded_file($_FILES["file"]["tmp_name"], $target_path)) && ($_FILES["file"]["type"] == "text/plain") || ($_FILES["file"]["type" == "images/jpeg")) {echo "success";} else { echo "failed";}?>[/code] if i don't make the third condition it works but i know that it should work it would be a great help if someone can tell me wts wrong with this scriptby the i get this error[quote]Parse error: parse error, unexpected ')', expecting ']' in E:\server\htdocs\upload.php on line 4[/quote] Link to comment https://forums.phpfreaks.com/topic/29033-whats-wrong-with-this-pls/ Share on other sites More sharing options...
AbydosGater Posted November 30, 2006 Share Posted November 30, 2006 Your missing a ] in the "type" for images/jepg!! Link to comment https://forums.phpfreaks.com/topic/29033-whats-wrong-with-this-pls/#findComment-133020 Share on other sites More sharing options...
jesi Posted November 30, 2006 Author Share Posted November 30, 2006 oh ya thanx that workedby the way i have written it to work for only.txt and .jpg i m practisingbut when i upload .txt files result comes success and when i upload .jpg it results failedwt could be the problem Link to comment https://forums.phpfreaks.com/topic/29033-whats-wrong-with-this-pls/#findComment-133023 Share on other sites More sharing options...
Psycho Posted November 30, 2006 Share Posted November 30, 2006 Could it be the missing left bracket?if ((move_uploaded_file($_FILES["file"]["tmp_name"], $target_path)) && ($_FILES["file"]["type"] == "text/plain") || ($_FILES["file"]["type"[b][color=red]][/color][/b] == "images/jpeg"))Also, the logic is off, I believe. The logic is read from left to right. So the way it is written the condition will pass if(move_uploaded_files is true AND the name is "text/plain") OR (the name is "images/jpeg")I think what you want is this:if ( move_uploaded_file($_FILES["file"]["tmp_name"], $target_path) && ( ($_FILES["file"]["type"] == "text/plain") || ($_FILES["file"]["type"] == "images/jpeg") ) ) EDIT: I'm surprised that jpeg files would fail with what you had originally. Anyway, try what I posted above, I think that will work for you. Link to comment https://forums.phpfreaks.com/topic/29033-whats-wrong-with-this-pls/#findComment-133024 Share on other sites More sharing options...
jesi Posted November 30, 2006 Author Share Posted November 30, 2006 no it still results success for .txt and failed for .jpg Link to comment https://forums.phpfreaks.com/topic/29033-whats-wrong-with-this-pls/#findComment-133026 Share on other sites More sharing options...
Psycho Posted November 30, 2006 Share Posted November 30, 2006 Try adding this just before the if statement and upload a jpeg. what is printed to the page[code]echo $_FILES["file"]["type"];[/code] Link to comment https://forums.phpfreaks.com/topic/29033-whats-wrong-with-this-pls/#findComment-133028 Share on other sites More sharing options...
jesi Posted November 30, 2006 Author Share Posted November 30, 2006 it printsimage/jpeg andfailed Link to comment https://forums.phpfreaks.com/topic/29033-whats-wrong-with-this-pls/#findComment-133030 Share on other sites More sharing options...
jesi Posted November 30, 2006 Author Share Posted November 30, 2006 i got it the mistake wasimages/jpegit should beimage/jpegthanx for the help and sorry for the double post was a bit in hurrysorry again Link to comment https://forums.phpfreaks.com/topic/29033-whats-wrong-with-this-pls/#findComment-133034 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.