jalen Posted May 27, 2009 Share Posted May 27, 2009 if (move_uploaded_file($_FILES['uploaded']['tmp_name'], $target) Could someone explain in detail what this code does, all I know generally is that this code let us know that if a file is uploaded, and if it is then do something. Also how do you do the reverse, how do you know if someone didn't upload a file then press the submit button? thx Quote Link to comment https://forums.phpfreaks.com/topic/159793-if-move_uploaded_file_filesuploadedtmp_name-target/ Share on other sites More sharing options...
tecmeister Posted May 27, 2009 Share Posted May 27, 2009 Hi, That moves the uploaded file from where it is tempory stored to the $target (where you want it to be stored) Quote Link to comment https://forums.phpfreaks.com/topic/159793-if-move_uploaded_file_filesuploadedtmp_name-target/#findComment-842808 Share on other sites More sharing options...
Maq Posted May 27, 2009 Share Posted May 27, 2009 Hi, That moves the uploaded file from where it is tempory stored to the $target (where you want it to be stored) tecmeister, you essentially repeated what the OP stated they already knew. Could someone explain in detail what this code does That's what the manual is for: - move_uploaded_file - $_FILES Also how do you do the reverse, how do you know if someone didn't upload a file then press the submit button? Maybe this will help: if (move_uploaded_file($_FILES['uploaded']['tmp_name'], $target) { //on success } else { //on failure } Quote Link to comment https://forums.phpfreaks.com/topic/159793-if-move_uploaded_file_filesuploadedtmp_name-target/#findComment-842811 Share on other sites More sharing options...
jalen Posted May 27, 2009 Author Share Posted May 27, 2009 Mag, I know that, but I am wondering if there is a code that say if someone didn't click on the browse button and therefor no files is attached, then do something. Like is there a code to know if someone didn't press the browse button or a file is not attached. B/c sometimes I don't have any files attached and the code: (move_uploaded_file($_FILES['uploaded']['tmp_name'], $target) would return true. and it will print out blanks. Quote Link to comment https://forums.phpfreaks.com/topic/159793-if-move_uploaded_file_filesuploadedtmp_name-target/#findComment-842832 Share on other sites More sharing options...
tecmeister Posted May 27, 2009 Share Posted May 27, 2009 I would do: if(empty($_FILES['uploaded]['name'])){ header("Location: destination.php?error=file_empty"); } destination.php page if(isset($_GET['error'])){ if($_GET['error'] == "file_empty"){ echo "file EMPTY"; } } Quote Link to comment https://forums.phpfreaks.com/topic/159793-if-move_uploaded_file_filesuploadedtmp_name-target/#findComment-842839 Share on other sites More sharing options...
jalen Posted May 27, 2009 Author Share Posted May 27, 2009 This is what I am trying to do, I have a upload field with a browse button for people to look for file. Then I have two fields, one is subject, and one is comments, then last but not least I have submitted button. What I want to do is this: there are a few scenario that could happen when the user use it. one: user could just upload files and have no subject and comment: (this should only upload the files and have no comments sub posted) two: user could upload files and have subject and comments: (this should show both files uploaded and comments/ subjects etc.) three: user did not upload files but just have subject and comments: (this should only show the comments and subject posted and no files uploaded) these three scenario are good and works: but there are chances where a user may upload and just input the sub or comments ONLY OR there are chances where a user may not upload anything and just enter the subject or comments ONLY and this should not work at all. I have set up the code to do this, but I am only stuck when I need to know if a file is not attached inverse of this code: if (move_uploaded_file($_FILES['uploaded']['tmp_name'], $target) if(empty($_FILES['uploaded]['name'])){ What is the 'name' here thanks Quote Link to comment https://forums.phpfreaks.com/topic/159793-if-move_uploaded_file_filesuploadedtmp_name-target/#findComment-842853 Share on other sites More sharing options...
tecmeister Posted May 27, 2009 Share Posted May 27, 2009 Will you be able to display the script you are using. This way I will be able to understand how you are trying to do it so far. Quote Link to comment https://forums.phpfreaks.com/topic/159793-if-move_uploaded_file_filesuploadedtmp_name-target/#findComment-842854 Share on other sites More sharing options...
jalen Posted May 27, 2009 Author Share Posted May 27, 2009 if (move_uploaded_file($_FILES['uploaded']['tmp_name'], $target) and ($comments=="" and $subject=="")){ mysql_query("insert into l_name(name) values('$fileName')"); $insert_name = 1; }elseif (move_uploaded_file($_FILES['uploaded']['tmp_name'], $target) and ($comments<>"" and $subject<>"")){ mysql_query("insert into l_name(name) values('$fileName')"); $insert_name = 1; mysql_query("insert into l_comments(comments, subject) values( '$comments', '$subject')"); }elseif (empty($files['uploaded']['tmp_name']) and ($comments<>"" and $subject<>"")) { mysql_query("insert into l_comments(comments, subject) values( '$comments', '$subject')"); } This is what I have, the 2nd elseif condition never runs properly for some reason I don't know why. And then I changed it to make it all not as if elseif but just if and still didn't run properly. what I mean by it didn't run properly is that when I upload a file and filled in the comments and subject field it should post both the file and sub/comment but it didn't. thx Quote Link to comment https://forums.phpfreaks.com/topic/159793-if-move_uploaded_file_filesuploadedtmp_name-target/#findComment-842856 Share on other sites More sharing options...
jalen Posted May 27, 2009 Author Share Posted May 27, 2009 BUMP Quote Link to comment https://forums.phpfreaks.com/topic/159793-if-move_uploaded_file_filesuploadedtmp_name-target/#findComment-843634 Share on other sites More sharing options...
grissom Posted May 27, 2009 Share Posted May 27, 2009 Try putting a debugging statement (a simple echo 'We are in here'; ) statement inside the second elseif to see if (1) you are actually getting into that bit of the code OR (2) whether you are getting in there but the mysql statements arent functioning properly Quote Link to comment https://forums.phpfreaks.com/topic/159793-if-move_uploaded_file_filesuploadedtmp_name-target/#findComment-843656 Share on other sites More sharing options...
J-C Posted March 11, 2010 Share Posted March 11, 2010 I KNOW THIS IS GRAVE DIGGING, but I was browsing through Google for some help and I decided to help the poster, Again sorry for grave digging. What you want to do is use isset(), or check if the $_POST/$_GET == 'NULL', again sorry for grave digging, I'm probably going to get flamed... Quote Link to comment https://forums.phpfreaks.com/topic/159793-if-move_uploaded_file_filesuploadedtmp_name-target/#findComment-1024980 Share on other sites More sharing options...
J-C Posted March 11, 2010 Share Posted March 11, 2010 damn could not edit post... use empty it works best... Quote Link to comment https://forums.phpfreaks.com/topic/159793-if-move_uploaded_file_filesuploadedtmp_name-target/#findComment-1024992 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.