Loading ...
Sorry, an error occurred while loading the content.

How to import word doc file into mysql table using php coding

Expand Messages
  • Gangadhara Prasad
    Hi Experts, How to import word doc file into mysql table using php coding? Can you please me anyone. Thanks, Gangadhar Meet people who discuss and share your
    Message 1 of 2 , May 30, 2008
    • 0 Attachment
      Hi Experts,

      How to import word doc file into mysql table using php coding?

      Can you please me anyone.

      Thanks,
      Gangadhar


      Bollywood, fun, friendship, sports and more. You name it, we have it.
    • Udaya kumar
      Hi GP, You can save anytype file in your MySQL table of field type BLOB. Table Structure: CREATE TABLE `imgtable` (`id` int(11) NOT NULL auto_increment, `name`
      Message 2 of 2 , Jun 4, 2008
      • 0 Attachment
        Hi GP,

        You can save anytype file in your MySQL table of field type BLOB.

        Table Structure:
        CREATE TABLE `imgtable` (`id` int(11) NOT NULL auto_increment, `name` varchar(30) NOT NULL,`type` varchar(30) NOT NULL,`size` int(11) NOT NULL,`content` mediumblob NOT NULL,  PRIMARY KEY  (`id`));

        Note: Here you go to store your word doc file in the content field and file mime type in the type field.

        PHP code for storing any type of file in the MYSQL Table:
        <?php

        require_once("dbconnection.php");

        if(isset($_POST['uploadfile']) && $_FILES['imagefile']['size'] > 0) {
            $fName = $_FILES['imagefile']['name'];
            $ftName = $_FILES['imagefile']['tmp_name'];
            $fSize = $_FILES['imagefile']['size'];
            $fType = $_FILES['imagefile']['type'];

            $fp      = fopen($ftName, 'r');
            $fcontent = fread($fp, filesize($ftName));
            $fcontent = addslashes($fcontent);
            fclose($fp);

            if (!get_magic_quotes_gpc()) {
                $fName = addslashes($fName);
            }

            $sql = "INSERT INTO imgtable (name, size, type, content ) VALUES ('$fName', '$fSize', '$fType', '$fcontent')";
            $result = mysql_query($sql, $connect) or die(mysql_error());
            $nrow = mysql_affected_rows($connect);

            if ($nrow > 0) {
                echo "<br>File ".$fName." could be uploaded.<br>";
                echo '<br><br><br><br><a href="StoreImage_Table.php">Back</a><br><br>';
            }
            else {   
                echo "<br>File ".$fName." could not be uploaded.<br>";
                echo '<br><br><br><br><a href="StoreImage_Table.php">Back</a><br><br>';
                exit();
            }
        }
        ?>

        PHP code for retrieving any type of file from the MYSQL Table:
        <?php
            require_once("dbconnection.php");

            // $filelist -> which is the file you want to retrieve...
            $sql = "SELECT name, type, size, content FROM imgtable WHERE id = '$filelist'";
            $result = mysql_query($sql) or die('Error, query failed');
            $nrow = mysql_affected_rows($connect);
            if ($nrow > 0) {
                $row = mysql_fetch_array($result);
                $name = $row['name'];
                $type = $row['type'];
                $size = $row['size'];
                $content = $row['content'];
                header("Content-length: $size");
                header("Content-type: $type");
                header("Content-Disposition: attachment; filename=$name");
                echo $content;
                exit;
            }
        ?>

        I hope that this will fulfill your requirements.
         
        Thanks & Regards
        Udayakumar Sarangapani
        Sr. PHP Developer
        CompIndia Infotech Pvt. Ltd.
        Chennai.

        "Science is nothing but logic..."



        ----- Original Message ----
        From: Gangadhara Prasad <lampprogramming@...>
        To: php-gurus <php-gurus@yahoogroups.com>; php-list <php-list@yahoogroups.com>; php4india <php4india@yahoogroups.com>; phpresource <phpresource@yahoogroups.com>
        Sent: Saturday, 31 May, 2008 8:27:54 AM
        Subject: [php4india] How to import word doc file into mysql table using php coding

        Hi Experts,

        How to import word doc file into mysql table using php coding?

        Can you please me anyone.

        Thanks,
        Gangadhar


        Bollywood, fun, friendship, sports and more. You name it, we have it.


        Unlimited freedom, unlimited storage. Get it now
      Your message has been successfully submitted and would be delivered to recipients shortly.