Additional PHP MySQL Data Processing of Uploaded Files

Last post 11-02-2012, 8:39 AM by PaulARLowe. 4 replies.
Sort Posts: Previous Next
  •  10-29-2012, 7:32 AM 75094

    Additional PHP MySQL Data Processing of Uploaded Files

    I am planning on using the Multiple File Upload capabability of phpfileuploader.  Is there a point at which I could intercept the code to carry out a PHP MySQL data operation immediately after each file is uploaded.  I would like to access the file name and register it in a database.

     

    Thank you.

    Filed under:
  •  10-29-2012, 10:27 AM 75099 in reply to 75094

    Re: Additional PHP MySQL Data Processing of Uploaded Files

    Hi PaulARLowe,

     

    Please try the example below, the red code will fire for each file. and you can get the upload file name by $mvcfile->FileName.

     

    1. <?php require_once "phpuploader/include_phpuploader.php" ?>  
    2. <?php session_start(); ?>  
    3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">  
    4. <html xmlns="http://www.w3.org/1999/xhtml">  
    5. <head>  
    6.     <title>  
    7.         example  
    8.     </title>  
    9.     <link href="demo.css" rel="stylesheet" type="text/css" />  
    10. </head>  
    11. <body>  
    12.             <form id="form1" method="POST">  
    13.                 <?php  
    14.   
    15.                 $uploader=new PhpUploader();  
    16.                 $uploader->MaxSizeKB=10240;  
    17.                 $uploader->MultipleFilesUpload=true;  
    18.                 $uploader->Name="myuploader";  
    19.                 $uploader->InsertText="Select multiple files (Max 10M)";  
    20.                 $uploader->AllowedFileExtensions="*.jpg,*.png,*.gif,*.bmp,*.txt,*.zip,*.rar";      
    21.                 $uploader->Render();  
    22.   
    23.                 ?>  
    24.                   
    25.                 <br/><br/><br/>  
    26.                   
    27. <?php  
    28.   
    29. $files=array();  
    30.   
    31. $processedlist=@$_POST["processedlist"];  
    32. if($processedlist)  
    33. {  
    34.     $guidlist=explode("/",$processedlist);  
    35.     foreach($guidlist as $fileguid)  
    36.     {  
    37.         $mvcfile=$uploader->GetUploadedFile($fileguid);  
    38.         if($mvcfile)  
    39.         {  
    40.             array_push($files,$mvcfile);  
    41.         }  
    42.     }  
    43. }  
    44. $fileguidlist=@$_POST["myuploader"];  
    45. if($fileguidlist)  
    46. {  
    47.     $guidlist=explode("/",$fileguidlist);  
    48.     foreach($guidlist as $fileguid)  
    49.     {  
    50.         $mvcfile=$uploader->GetUploadedFile($fileguid);  
    51.         if($mvcfile)  
    52.         {  
    53.             //Process the file here..  
    54.             //rename(..)  
    55.               
    56.             if($processedlist)  
    57.                 $processedlist$processedlist . "/" . $fileguid;  
    58.             else  
    59.                 $processedlist$fileguid;  
    60.           
    61.             array_push($files,$mvcfile);  
    62.         }  
    63.     }  
    64. }  
    65.   
    66. if(count($files)>0)  
    67. {  
    68.     foreach($files as $mvcfile)  
    69.     {  
    70.         //$mvcfile->FileName is the original file name  
    71.         //save the upload file into D:/sites/phpuploader/test/  
    72.         $mvcfile->CopyTo("D:/sites/phpuploader/test/".$mvcfile->FileName);   
    73.     }  
    74. }  
    75.   
    76. ?>  
    77.               
    78.             </form>  
    79.   
    80. </body>  
    81. </html>  
     

    Regards,

     

    Ken 

  •  10-31-2012, 9:51 AM 75120 in reply to 75099

    Re: Additional PHP MySQL Data Processing of Uploaded Files

    Ken:

    Thank you very much.  After some manipulation I got the code to do exactly as I wanted.  There is only 1 issue however, although I get the progress table and status bar as the files are uploading, they disappear after the files are uploaded leaving only the "Select Multiple Files" button.  Is there a way to prevent the progress table results from being erased?  The code that I have added is:

     

    if(count($files)>0)  
        {  
            //Login and Connect to database
            //*********************************************************
           //Code here deleted for security but it works as the correct data for all files is being inserted into the database correctly 
          
            foreach($files as $mvcfile)  
            {  
                //$mvcfile->FileName is the original file name  
                $filename=$mvcfile->FileName;   
                $newspaper=substr($filename,0,2);
                $year=substr($filename,3,4);
                $month=substr($filename,8,2);
                $day=substr($filename,11,2);
                $page=substr($filename,14,strpos($filename,".")-14);
                
                $insertfile="INSERT INTO m_newspaperarchives(newspaper,year,month,day,page,filename) VALUES             ('$newspaper','$year','$month','$day','$page','$filename')"; 
                $insertfile2=mysql_query($insertfile) or die("<br />Could not insert file data into m_newspaperarchives table<br />");
            } 
    Best regards, Paul
     

     

  •  11-01-2012, 8:29 AM 75133 in reply to 75120

    Re: Additional PHP MySQL Data Processing of Uploaded Files

    Hi PaulARLowe,

     

    If the code use in a <from> and do a post back to submit the data, then you need to generate the attachment table by some code. 

     

    Please refer to example page "ajax-attachments.php", it shows you how to generate the attachment table.

     

    Regards,

     

    Ken 

  •  11-02-2012, 8:39 AM 75138 in reply to 75133

    Re: Additional PHP MySQL Data Processing of Uploaded Files

    Thanks Ken.  I'll give that a try.

     

    Best regards, Paul

View as RSS news feed in XML