Jump to content


Photo

upload multiple files


  • Please log in to reply
No replies to this topic

#1 mariocesar

mariocesar
  • Members
  • PipPipPip
  • Advanced Member
  • 84 posts

Posted 17 March 2006 - 07:46 PM

this script save some information in a dbase and upload a file, using a class, how can I make it work for upload multiple files lets said 3 files, I got the form but only the last file is uploaded.

thanks

[/code]

and this is the php//


<? 
/* grabs the POST variables and puts them into variables that we can use */ 
$f1=$_POST['f1'];
$f9=$_POST['f9'];
$f11=$_POST['f11'];
$f10=$_POST['f10'];
$f2=$_POST['f2'];
$f3=$_POST['f3'];
$f4=$_POST['f4'];
$f5=$_POST['f5'];
$f8=$_POST['f8'];
//---------VALIDATION--------> 
   if($f2){//----> CHECK input 
        } 
        else{ 
            $error.="";//----> ERROR if no input 
            } 
    

    
//-------->ERROR FREE?? 
    if($error==""){ 
        echo "Thank you! A receipt of your submission will be e-mailed to you immediately."; 
//---------------------------------- 

//--->echo $mailContent; 
$mailContent="--------Contact--------\n" 
            ."Name: ".$f1."\n" 
            ."Company: ".$f9."\n\n--------Addressing--------\n" 
            ."E-mail: ".$f2."\n" 
            ."Phone: ".$f10."\n\n--------Description--------\n"
            ."Description: ".$f8."\n";
//---------------------------------- 
$toAddress="upload@copymailforyou.com"; /* change this! */ 
$subject="Copyroom.com Addressing Upload"; /* change this! */ 
$recipientSubject="Copyroom.com Upload Form"; /* change this! */ 
$receiptMessage = "Thank you ".$user." for upload a file.\n\n\nHere is what you submitted to us:\n\n" 
            ."--------Contact--------\n" 
            ."Name: ".$f1."\n" 
            ."Company: ".$f9."\n\n--------Addressing--------\n" 
            ."E-mail: ".$f2."\n" 
            ."Phone: ".$f10."\n\n--------Description--------\n"
            ."Description: ".$f8."\n";
//---------------------------------- 
mail($f2, $subject, $receiptMessage,"From:$toAddress"); 
//---------------------------------- 
mail($toAddress,$recipientSubject,$mailContent,"From:$f2"); 
//--->echo $mailContent; 


////////////////////////////////////////  CONNECT TO MYSQL DB  //////////////////// 
// OPEN CONNECTION ---> 
$connection=mysql_connect('mysql77.secureserver.net', $user = "multifiles", $pass = "multifiles") or die("Unable to connect!"); /* change this! */ 

mysql_select_db("multifiles") or die("Unable to select database!"); /* change this! */ 

//  EXECUTE QUERY ---> 
$query="INSERT INTO multifiles ( f1, f9, f11, f10, f2, f3, f4, f5, f8) 
        VALUES( '".$f1."', '".$f9."', '".$f11."', '".$f10."', '".$f2."', '".$f3."', '".$f4."', '".$f5."' , '".$f8."')"; 
//////-----> 
$result=mysql_query($query) or die("Error in query:".mysql_error()); 
//if ($result) 
    //echo mysql_affected_rows()." row inserted into the database effectively."; 

//  CLOSE CONNECTION ---> 
mysql_close($connection); 
 
        } 
    else{ 

            print "Sorry, but the form cannot be sent until the fields indicated are filled out completely - <br>\n"; 
            print "$error<br>\n"; 
            print "<br>\n"; 
            print "<br>\n"; 
            print "Please use your \"Back\" button to return to the form to correct the omissions.  Thank you.<br>\n"; 
        } 
?>
<?php
include ("uploadclass.php"); 
$upload_class = new FileUpload; 
$upload_class->temp_file_name = trim($_FILES['upload']['tmp_name']); 
$upload_class->file_name = trim(strtolower($_FILES['upload']['name'])); 
$upload_class->upload_dir = "php_uploads/"; 
$upload_class->upload_log_dir = "php_uploads/upload_logs/"; 
$upload_class->max_file_size = 5242880; 
$upload_class->banned_array = array(""); 
$upload_class->ext_array = array(".zip",".rar",".ace",".tar",".doc",".txt",".csv",".xls",".ppt"); 

$valid_ext = $upload_class->validate_extension(); 
$valid_size = $upload_class->validate_size(); 
$valid_user = $upload_class->validate_user(); 
$max_size = $upload_class->get_max_size(); 
$file_size = $upload_class->get_file_size(); 
$file_exists = $upload_class->existing_file(); 

    if (!$valid_ext) { 
        $result = "The file extension is invalid, please try again!"; 
    } 
    elseif (!$valid_size) { 
        $result = "The file size is invalid, please try again! The maximum file size is: $max_size and your file was: $file_size"; 
    } 
    elseif (!$valid_user) { 
        $result = "You have been banned from uploading to this server."; 
    } 
    elseif ($file_exists) { 
        $result = "This file already exists on the server, please try again."; 
    } else { 
        $upload_file = $upload_class->upload_file_with_validation(); 
        if (!$upload_file) { 
            $result = "Your file could not be uploaded!"; 
        } else { 
            $result = "Your file has been successfully uploaded to the server."; 
        } 
    } 
    echo $result;
?>

this is the form//

<FORM name=uploadfrm onsubmit="return checkfields(uploadfrm);" 
              action=multifiles.php method=post 
              encType=multipart/form-data><INPUT type=hidden 
              value=/upload/index.php name=formurl> <INPUT type=hidden 
              value=1048576000 name=MAX_FILE_SIZE> <INPUT type=hidden 
              value=upload name=mode> <INPUT type=hidden 
              value=9f5f69a41c20742ef84371dda13ce7e0 name=PHPSESSID> 
              <TBODY>
              <TR>
                <TD vAlign=center><B><FONT 
                  style="FONT-SIZE: 13px; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif">Full 
                  Name</B>*<BR><FONT 
                  style="FONT-SIZE: 10px; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif"></FONT></FONT></TD>
                <TD width=5></TD>
                <TD 
                style="FONT-SIZE: 13px; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif" 
                vAlign=center><INPUT 
                  style="FONT-SIZE: 13px; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif" 
                  maxLength=50 size=40 name=f1></TD></TR>
              <TR>
                <TD vAlign=center><B><FONT 
                  style="FONT-SIZE: 13px; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif">Company 
                  Name</B><BR><FONT 
                  style="FONT-SIZE: 10px; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif"></FONT></FONT></TD>
                <TD width=5></TD>
                <TD 
                style="FONT-SIZE: 13px; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif" 
                vAlign=center><INPUT 
                  style="FONT-SIZE: 13px; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif" 
                  maxLength=1000 size=40 name=f9></TD></TR>
              <TR>
                <TD vAlign=center><B><FONT 
                  style="FONT-SIZE: 13px; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif">Your 
                  Contact Person</B>*<BR><FONT 
                  style="FONT-SIZE: 10px; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif"></FONT></FONT></TD>
                <TD width=5></TD>
                <TD 
                style="FONT-SIZE: 13px; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif" 
                vAlign=center><INPUT 
                  style="FONT-SIZE: 13px; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif" 
                  maxLength=1000 size=40 name=f11></TD></TR>
              <TR>
                <TD vAlign=center><B><FONT 
                  style="FONT-SIZE: 13px; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif">Phone 
                  Number</B>*<BR><FONT 
                  style="FONT-SIZE: 10px; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif"></FONT></FONT></TD>
                <TD width=5></TD>
                <TD 
                style="FONT-SIZE: 13px; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif" 
                vAlign=center><INPUT 
                  style="FONT-SIZE: 13px; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif" 
                  maxLength=1000 size=40 name=f10></TD></TR>
              <TR>
                <TD vAlign=center><B><FONT 
                  style="FONT-SIZE: 13px; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif">Email 
                  Address</B>*<BR><FONT 
                  style="FONT-SIZE: 10px; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif"></FONT></FONT></TD>
                <TD width=5></TD>
                <TD 
                style="FONT-SIZE: 13px; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif" 
                vAlign=center><INPUT 
                  style="FONT-SIZE: 13px; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif" 
                  maxLength=50 size=40 name=f2></TD></TR>
              
              
              <TR>
                <TD vAlign=top><B><FONT 
                  style="FONT-SIZE: 13px; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif">Description</B><BR><FONT 
                  style="FONT-SIZE: 10px; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif"></FONT></FONT></TD>
                <TD width=5></TD>
                <TD 
                style="FONT-SIZE: 13px; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif" 
                vAlign=top><TEXTAREA style="FONT-SIZE: 13px; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif" name=f8 rows=7 cols=39></TEXTAREA></TD></TR>
              <TR>
                <TD vAlign=center><B><FONT 
                  style="FONT-SIZE: 13px; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif">File 
                  #1</B>*<BR><FONT 
                  style="FONT-SIZE: 10px; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif"></FONT></FONT></TD>
                <TD width=5></TD>
                <TD 
                style="FONT-SIZE: 13px; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif" 
                vAlign=center><INPUT TYPE="HIDDEN" NAME="MAX_FILE_SIZE" VALUE="900000">
<input name="upload" type="file" size="30"></TD></TR>
<TR>
                <TD vAlign=center><B><FONT 
                  style="FONT-SIZE: 13px; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif">File 
                  #2</B><BR><FONT 
                  style="FONT-SIZE: 10px; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif"></FONT></FONT></TD>
                <TD width=5></TD>
                <TD 
                style="FONT-SIZE: 13px; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif" 
                vAlign=center><INPUT TYPE="HIDDEN" NAME="MAX_FILE_SIZE" VALUE="900000">
<input name="upload" type="file" size="30"></TD></TR>
             <TR>
                <TD vAlign=center><B><FONT 
                  style="FONT-SIZE: 13px; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif">File 
                  #3</B><BR><FONT 
                  style="FONT-SIZE: 10px; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif"></FONT></FONT></TD>
                <TD width=5></TD>
                <TD 
                style="FONT-SIZE: 13px; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif" 
                vAlign=center><INPUT TYPE="HIDDEN" NAME="MAX_FILE_SIZE" VALUE="900000">
<input name="upload" type="file" size="30">
</p>
    <p align="center"> 
    <input type="submit" name="Submit" value="Upload">  
    </p>

                </TD></TR></FORM





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users