Jump to content

if (move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)


jalen

Recommended Posts

 

  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

 

Link to comment
Share on other sites

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
}

 

 

Link to comment
Share on other sites

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. 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

     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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • 9 months later...

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...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.