Page 1 of 1
Uploading two files at a time
Posted: Mon Feb 27, 2006 4:12 am
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...
Posted: Mon Feb 27, 2006 4:18 am
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;
}
Posted: Mon Feb 27, 2006 4:35 am
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...