Uploading two files at a time

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
bugthefixer
Forum Contributor
Posts: 118
Joined: Mon Mar 22, 2004 2:35 am

Uploading two files at a time

Post by bugthefixer »

Here is the code that i am using to upload two files

Code: Select all

if(copy($_FILES['tfile1']['tmp_name'], $the_path))
		{
		
			if(copy($_FILES['tfile1']['tmp_name'], $the_path_2))
				{
		
   				echo "File is valid, and was successfully uploaded.\n";
				}
			else
				echo "file cannot be uploaded";
		} 
		else
				echo "file 2 cannot be uploaded in";
When I comment out code for one file the other file is uploaded... but both of them cannot be uploaded at a time..... I have also used Pear Upload method but the same prolem is there .... I cant upload two files at a time.. Is there any solution to this.. is there something that i am missing...
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Post by jayshields »

You do know you are uploading the same file to 2 seperate paths, you're not uploading 2 seperate files. You have missed alot of curly brackets, these probably don't produce syntax errors but they make for hard debugging.

Also, you're copying the uploaded files from the temp directories instead of moving them.

Try this:

Code: Select all

if(move_uploaded_file($_FILES['tfile1']['tmp_name'], $the_path)) {
  echo $_FILES['tfile1']['name'] . ' has been uploaded to ' . $the_path;
}

if(move_uploaded_file($_FILES['tfile1']['tmp_name'], $the_path2)) {
  echo $_FILES['tfile1']['name'] . ' has been uploaded to ' . $the_path2;
}
bugthefixer
Forum Contributor
Posts: 118
Joined: Mon Mar 22, 2004 2:35 am

Post by bugthefixer »

well i have tried move_uploaded_file as well but in this case i get Access Denied Error.
Ok here's the complete code

Code: Select all

$fname = $_FILES['tfile']['name'];
	$pdfName = $_FILES['tfile2']['name'];
$the_path = "../../uploadimages/"  . $fname;
	$the_path_2 = "../../uploadimages/" . $pdfName;

			
			

		if(copy($_FILES['tfile']['tmp_name'], $the_path))
		{
		

			if(copy($_FILES['tfile2']['tmp_name'], $the_path_2))
				{
				
				$UserID = $_SESSION['userid'];
				$tdesc = addslashes($tdesc);
				$iq = "insert into wenimage (gallery_id, sub_gallery_id, imagetitle, description, imagefile, pdffile, dateuploaded,user_id) values ($cboGallery, $cboSubGallery, '$ttitle', '$tdesc', '$fname', '$pdfName',NOW(), $UserID)";
			
				$irs = wendbquery($conn, $iq);
				$iq = "select max(imageid) from wenimage";

				$irs = wendbquery($conn, $iq);

				$idr = mysql_fetch_row($irs);



				$newName =  $dirPath . $idr[0] . $fname;
				$newName2 =  $pdfPath . $idr[0] . $pdfName;

				rename($the_path ,$newName);
				rename($the_path_2 ,$newName2);
   				
				
			}
On renaming the second file it says access denied...
Post Reply