Break 1 File Into 2

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
billhobbs
Forum Newbie
Posts: 11
Joined: Thu Apr 27, 2006 4:08 pm

Break 1 File Into 2

Post by billhobbs »

I want to break this upload process so that instead of being in 1 file it actually goes into 2, where the first file allows you to select the files to be uploaded and uploads the files when submitted. In the second file I only want to be able to see the information about the files. What the names are and if they were uploaded correctly. Can anyone help me with this?

Here is the code.

Code: Select all

<?
$num_of_uploads=10;
$file_types_array=array("jpg", "JPG", "pdf", "PDF");
$max_file_size=1048576;
$upload_dir="";

function uploaderFILES($num_of_uploads=1, $file_types_array=array("jpg", "JPG", "pdf", "PDF"), $max_file_size=1048576, $upload_dir=""){
  if(!is_numeric($max_file_size)){
   $max_file_size = 1048576;
  }
  foreach($_FILES["file"]["error"] as $key => $value)
  {
     if($_FILES["file"]["name"][$key]!="")
     {
       if($value==UPLOAD_ERR_OK)
       {
         $origfilename = $_FILES["file"]["name"][$key];
         $filename = explode(".", $_FILES["file"]["name"][$key]);
         $filenameext = $filename[count($filename)-1];
         unset($filename[count($filename)-1]);
         $filename = implode(".", $filename);
         $filename = substr($filename, 0, 15).".".$filenameext;
         $file_ext_allow = FALSE;
         for($x=0;$x<count($file_types_array);$x++){
           if($filenameext==$file_types_array[$x])
           {
             $file_ext_allow = TRUE;
           }
         } // for
         if($file_ext_allow){
           if($_FILES["file"]["size"][$key]<$max_file_size){
             if(move_uploaded_file($_FILES["file"]["tmp_name"][$key], $upload_dir.$filename)){
               echo("File Uploaded Successfully. - <a href='".$upload_dir.$filename."' target='_blank'>".$filename."</a><br />");
             } 
             else { echo('<font color="#FF0000">'.$origfilename."</font> Was Not Successfully Uploaded<br />");}
           }
           else  { echo('<font color="#FF0000">'.$origfilename."</font> Was Too Big, Not Uploaded<br />"); }
         } // if
         else{ echo('<font color="#FF0000">'.$origfilename." </font>Had An Invalid File Extension<br />");  }
       }
       else{ echo('<font color="#FF0000">'.$origfilename." </font>Was Not Successfully Uploaded<br />");  } // else
     }
  }
} // funtion


?>
		  <form action='<?=$PHP_SELF;?>' method='post' enctype='multipart/form-data' onSubmit="WA_setFormCookie(WA_CookieObj,document.forms[0],'WAFC_1CarUploadFiles_forms', );WA_setCookie(WA_CookieObj,'FilesUploaded',document.undefined.submitted.value,true,0,30)"><span class="Body">You may upload up to 10 files. They must all be in either Jpg or Pdf formats. All other types of files will be rejected by the server.</span> <br />
    <input type='hidden' name='submitted' value='TRUE' id='<?=time();?>'>
  <input type='hidden' name='MAX_FILE_SIZE' value='<?=$max_file_size;?>'>
  <br>
  <span class="Body">
  <?  for($x=0;$x<$num_of_uploads;$x++){
     $form .= "<input type='file' name='file[]'><br />";
   }
   $form .= "<input type='submit' value='Upload'><br />
   <font color='red'>*</font>Maximum file length (minus extension) is 15 characters. Anything over that will be cut to only 15 characters. Valid file type(s): ";
   for($x=0;$x<count($file_types_array);$x++){
     if($x<count($file_types_array)-1){
       $form .= $file_types_array[$x].", ";
     }else{
       $form .= $file_types_array[$x].".";
     }
   }
   echo($form);
?> 
   </span>                                
            </form>
  

			  <p>
			    <?
if(isset($_POST["submitted"])){
   uploaderFILES($num_of_uploads, $file_types_array, $max_file_size, $upload_dir);
}
?>
Post Reply