Jump to content

Archived

This topic is now archived and is closed to further replies.

jalen

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

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

 

Share this post


Link to post
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)

Share this post


Link to post
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
}

 

 

Share this post


Link to post
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. 

 

Share this post


Link to post
Share on other sites

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";

    }

}

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

damn could not edit post... use empty it works best...

Share this post


Link to post
Share on other sites

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