help with multiple file move

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dsick
Forum Commoner
Posts: 57
Joined: Fri Mar 27, 2009 3:34 pm

help with multiple file move

Post by dsick »

i plan on making this a single page submit when its working i will have this code wrapped around if(isset($_POST['submit'])) {

}

read my comment towards the move_uploaded_file function

right now.. it works.. but it only moves the $name file.. which is a psd... i want to also move the $gif file

Code: Select all

 
$name     = $_FILES["myfile"]["name"];
$gif      = $_FILES["gif"]["name"];
$type     = $_FILES["myfile"]["type"];
$size     = $_FILES["myfile"]["size"];
$tmp_name = $_FILES["myfile"]["tmp_name"];
$erro     = $_FILES["myfile"]["error"];
 
 
if ($error > 0 )
die("sory can't upload file code $error");
 
else
{
 
 
if ($size > 1000000)
{
die("that file is not allowed or the size is to big");
 
}
else
{
 
 
 
move_uploaded_file($tmp_name, "images/" .$name); 
 
//it works up untill this point..... the $name file is created but not the $gif file
move_uploaded_file($tmp_name, "images/" .$gif);
 
 
 
}
 
 
 
 
 
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("community") or die(mysql_error());
mysql_query("INSERT INTO psds
(author, name_psd, name_gif) VALUES('scott33', '$name','$gif') ") 
or die(mysql_error());
}
 
 
 
 
 
 
 
?>
 
 

heres my upload form

Code: Select all

 
<html>
<h1>Upload A File</h1>
 
 
 
<form action='upload.php' method='POST' enctype='multipart/form-data'>
 
 
Name<p>    
<input type='text' name='name'><p>
 
Description<p>    
<input type='text' name='desc'><p>
 
step 1: upload a psd
<input type='file' name='myfile'><p>
 
step 2: upload the png or gif
<input type='file' name='gif'><p>
 
<input type='submit' value='upload'>
 
</form>
 
</html>
 
 
unless there is a way to view PSD files with php.. i will have to upload 2 different files.. most PSD sites only have one tho which is PNG.. and you download the PSD
MichaelR
Forum Contributor
Posts: 148
Joined: Sat Jan 03, 2009 3:27 pm

Re: help with multiple file move

Post by MichaelR »

Code: Select all

 
move_uploaded_file($tmp_name, "images/" .$name);
 
//it works up untill this point..... the $name file is created but not the $gif file
move_uploaded_file($tmp_name, "images/" .$gif);
 
What is $tmp_name?

Code: Select all

$tmp_name = $_FILES["myfile"]["tmp_name"];
So, add $gif_temp = $_FILES["gif"]["tmp_name"];, and then use this:

Code: Select all

 
move_uploaded_file($tmp_name, "images/" .$name);
 
//it works up untill this point..... the $name file is created but not the $gif file
move_uploaded_file($gif_temp, "images/" .$gif);
 
dsick
Forum Commoner
Posts: 57
Joined: Fri Mar 27, 2009 3:34 pm

Re: help with multiple file move

Post by dsick »

$tmp_name is the name myfile wich would be $tmp_psd if i was to re code it
MichaelR
Forum Contributor
Posts: 148
Joined: Sat Jan 03, 2009 3:27 pm

Re: help with multiple file move

Post by MichaelR »

Sorry, that was a rhetorical question. :wink:

What I was pointing out is that the code you have is only moving "my_file". Just to two different locations. You're moving it to images/my_file and images/gif. and I presume the second one fails because "my_file" is no longer there.

Instead of:

Code: Select all

move_uploaded_file($temp_name, "images/" .$gif);
You want:

Code: Select all

move_uploaded_file($gif_temp, "images/" .$gif);
Where:

Code: Select all

$gif_tmp = $_FILES["gif"]["tmp_name"];
Unless I'm the one making a mistake here. In which case: :oops:
dsick
Forum Commoner
Posts: 57
Joined: Fri Mar 27, 2009 3:34 pm

Re: help with multiple file move

Post by dsick »

i understanded what you where saying clearly it was a stupid mistake to think i didn't need a tmp name for both file inputs 8O '

and thus its working now.. thanks

just wish there was a better way where i wouldnt have to save to different files on my computer for one image....

i want to keep both of them move_uploaded_files... i add the $gif_tmp in there because i want to move the gif plus the psd to the images directory then save the entries to the database.. ima switch to mysqli tho because i just put the old fasion way in there to test it
Post Reply