Single File Uploads and Save into DB

Last post 11-23-2012, 9:06 AM by Jacques123. 4 replies.
Sort Posts: Previous Next
  •  11-20-2012, 6:34 AM 75289

    Single File Uploads and Save into DB

    Hi

    I'm reading alot about arays here and i think its not what i need

    I would like to do the following.

    Always Single file Uploads, Then Insert each filename into db and then refresh the page

     

    $uploader=new PhpUploader();
    $uploader->MultipleFilesUpload=false;
    $uploader->InsertText="Upload Another File (Max 10M)";
    $uploader->MaxSizeKB=1024000;    
    $uploader->AllowedFileExtensions="pdf";
    $BrokerUsername = $username;

    $uploader->SaveDirectory=$NewDirBrokerUploads;

    $uploader->Render();

     

    $filename = $mvcfile->FileName;

    if (!empty($filename)){
    $sqlinsert="INSERT INTO `uploads` (`id`, `username`, `filename`) VALUES ('NULL',".
    "'$username',". //username
    "'$filename');"; //filename
    mysql_query($sqlinsert, $link);

     

    header ('Location: brokerupload.php'); die (); exit (0);
     }

     

    But this does not work

    Can some help me with the correct code please.

     

  •  11-20-2012, 10:13 AM 75291 in reply to 75289

    Re: Single File Uploads and Save into DB

    Hi,

     

    Please try the way below

     

    <?php require_once "phpuploader/include_phpuploader.php" ?>
    <?php session_start(); ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
      <head>
        <title>
          example
        </title>
      </head>
      <body>


        <form id="form1" method="POST">
          <?php                       
                                  $uploader=new PhpUploader();
                                  $uploader->MaxSizeKB=10240;
                                  $uploader->Name="myuploader";
                                  $uploader->AllowedFileExtensions="*.pdf";     
                                  $uploader->Render();
                    ?>


        </form>




        <?php
    $fileguidlist=@$_POST["myuploader"];
    if($fileguidlist)
    {
    $guidlist=explode("/",$fileguidlist);  
        foreach($guidlist as $fileguid)   
        {   
           
            //get the uploaded file based on GUID      
            $mvcfile=$uploader->GetUploadedFile($fileguid);      
            if($mvcfile)      
            {      
              //save info into db here
            }   
        }   


    }
    ?>


        </div>
      </body>
    </html>
     

    Regards,

     

    Ken

  •  11-20-2012, 12:17 PM 75294 in reply to 75291

    Re: Single File Uploads and Save into DB

    Hi Ken

     

    I did exactly like you said here but it does not die my sql at the point where its suppose to insert into db.

    Which means its not getting to that point.

    I've added the form tags and all. Just like you said here

     

    Any ideas please

  •  11-21-2012, 10:27 AM 75313 in reply to 75294

    Re: Single File Uploads and Save into DB

    Hi Jacques123,

     

    Please create a new page with the code below, then send me the url of this page. I will check it and get back to you as soon as possible.

     

    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.   </head> 
    10.   <body> 
    11.  
    12.     <form id="form1" method="POST"
    13.       <?php               
    14.                     $uploader=new PhpUploader(); 
    15.                     $uploader->MaxSizeKB=10240; 
    16.                     $uploader->Name="myuploader"
    17.  
    18.                     $uploader->Render(); 
    19.             ?> 
    20.  
    21.     </form> 
    22.  
    23.  
    24.     <?php 
    25. $fileguidlist=@$_POST["myuploader"]; 
    26. if($fileguidlist
    27. $guidlist=explode("/",$fileguidlist);    
    28.     foreach($guidlist as $fileguid)     
    29.     {     
    30.          
    31.         //get the uploaded file based on GUID        
    32.         $mvcfile=$uploader->GetUploadedFile($fileguid);        
    33.         if($mvcfile)        
    34.         {        
    35.           echo "this is a test!"
    36.         }     
    37.     }     
    38.  
    39. ?> 
    40.  
    41.     </div> 
    42.   </body> 
    43. </html> 
     

    Regards,

     

    Ken

  •  11-23-2012, 9:06 AM 75341 in reply to 75313

    Re: Single File Uploads and Save into DB

    Hi Ken

     

    Thanks for the code. The part that was missing on my code was

     

    $uploader->Name="myuploader"; 

    Which made the @post part obviously not get triggered

     

    working now will let you know if i need other help 

View as RSS news feed in XML