Re: Insert filename, size file & modified date file into mysql database

  •  02-18-2011, 9:52 AM

    Re: Insert filename, size file & modified date file into mysql database

    Dear faisalmustaffa,
     
    Please refer to the following snippet:

    <?php require_once "phpuploader/include_phpuploader.php" ?>
    <?php session_start(); ?>
    <html>
    <head>
    <title>Example</title>
    </head>
    <body>
    <form name="theForm" action="1.php?postback=true" method="post">
    <h1>Example</h1>
    <table>
     <tr>
      <td>Subject:</td>
      <td><input name="subject" type="text" id="subject"
       style="width: 170px;" /></td>
     </tr>
     <tr>
      <td>From:</td>
      <td><input name="from" type="text" id="from" style="width: 170px;" />
      </td>
     </tr>
     <tr>
      <td>To:</td>
      <td><input name="to" type="text" id="to" style="width: 170px;" /></td>
     </tr>
    </table>
    <br />
    <br />
    <br />
    <?php
    $uploader=new PhpUploader();
    $uploader->MultipleFilesUpload=true;
    $uploader->Name="myuploader";
    $uploader->InsertText="Select multiple files (Max 1000M)";
    $uploader->MaxSizeKB=1024000;
    $uploader->Render();
    echo '<br \>';
    echo '<br \>';
    if(@$_POST["subject"]!=null)
    {
     echo $_POST["subject"];
     echo '<br \>';
    }
    if(@$_POST["from"]!=null)
    {
     echo $_POST["from"];
     echo '<br \>';
    }
    if(@$_POST["to"]!=null)
    {
     echo $_POST["to"];
     echo '<br \>';
    }
    $fileguid=@$_POST["myuploader"];   
    if($fileguid)   
    {   
        //get the uploaded file based on GUID   
        $mvcfile=$uploader->GetUploadedFile($fileguid);   
        if($mvcfile)   
        {   
            //Gets the name of the file.   
            echo($mvcfile->FileName);   
            echo "<br/>";
            //Gets the temp file path.   
            echo($mvcfile->FilePath);  
            echo "<br/>";
            //Gets the size of the file.   
            echo($mvcfile->FileSize);    
            echo "<br/>";
               
            //Copys the uploaded file to a new location.   
            //$mvcfile->CopyTo("/savefiles");  
           
            //Deletes this instance.   
            //$mvcfile->Delete();

            if ($mvcfile->FilePath<>""){
              $fp=fopen($mvcfile->FilePath,"r");
              $data=addslashes(fread($fp,filesize($mvcfile->FilePath)));
            $connect = @mysql_connect( "localhost", "root", "" );
          if ( ! $connect ) {
        die( "Couldn't connect to MySQL: ".mysql_error() );
       }
       $db = "cuteeditortest";
       @mysql_select_db( $db ) or die ( "Couldn't open $db: ".mysql_error() );
       $id=555;
          $sql="insert into image (id,photo) values('$id','$data')";
       
          mysql_query( $sql, $connect ) or die ( "INSERT error: ".mysql_error() );     
          mysql_close($connect);
            }
        }   
    }
    ?>
    </form>
    </body>
    </html>

    Thank you for asking
View Complete Thread