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

Re: [phpResource] Storing file in database

Expand Messages
  • Md. Aminul Islam
    Hi, nice solution. anyone knows what to do for Image(jpg, bmp, gif etc) or PDF files. aminul Mohamed BADR wrote: Hi Debasish i have made
    Message 1 of 6 , May 31, 2006
    • 0 Attachment
      Hi,
          nice solution. anyone knows what to do for Image(jpg, bmp, gif etc) or PDF files.
      aminul

      Mohamed BADR <badr@...> wrote:
      Hi Debasish
       
      i have made similar script before for the users to store their CVs word doc in the database
      here is my code it works 100% ;)
       
       
       
       <? if($action=="form"){?>
          <center> <p class="style4">To attach your CV to your CV website so it can be available for companies to download please upload it here </p>
           
          
                    <form action="<? print($PHP_SELF)?>" method="post" name="register" enctype="multipart/form-data">
                    <p class="help style4"><strong>File must be a microsoft word document (.doc) </strong></p>
                    <table width="90%" border="0" align="center">
                      <tr>
                        <td>Browse your CV </td>
                        <td><input type="hidden" name="MAX_FILE_SIZE" value="2000000">
      <input name="userfile" type="file" id="userfile">
      </td>
                      </tr>
                      <tr>
                        <td>&nbsp;</td>
                        <td> <input name="upload" type="submit"  id="upload" value="  Upload  "></td>
                      </tr>
                    </table> </form>
           <? }?>
           <?php
      if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0)
      {
      $fileName = $_FILES['userfile']['name'];
      $tmpName  = $_FILES['userfile']['tmp_name'];
      $fileSize = $_FILES['userfile']['size'];
      $fileType = $_FILES['userfile']['type'];
       
      $fp      = fopen($tmpName, 'r');
      $content = fread($fp, filesize($tmpName));
      $content = addslashes($content);
      fclose($fp);
       
      if(!get_magic_quotes_gpc())
      {
          $fileName = addslashes($fileName);
      }
       
       
       
      $query = "INSERT INTO seekers_cv (seeker_id,name, size, type, content ) ".
      "VALUES ('$juserid','$fileName', '$fileSize', '$fileType', '$content')";
       
      mysql_query($query) or die('Error, query failed');
       

      echo "<br>File $fileName uploaded<br>thank you";
      }
      ?>
      Mohamed BADR
      Senior Web/Database developer
      PHP/MySql/ Oracle  -  ASP.NET/SQL - multimedia
      OMEGA SOFT
      0102050009
      ----- Original Message -----
      Sent: Wednesday, May 31, 2006 9:46 PM
      Subject: [phpResource] Storing file in database

      Hi,

         In my project when a user will upload any file I
      want to store it in the database(not in any folder) &
      display the same file to the user at the time of
      fetching data.

         For example the user stored test.doc file while
      uploading.At the time of viewing the user should see
      it in same ".doc" format.

         Please help me in the above matter.

      Thanks
      Debasish

      Send instant messages to your online friends http://in.messenger.yahoo.com



      __________________________________________________
      Do You Yahoo!?
      Tired of spam? Yahoo! Mail has the best spam protection around
      http://mail.yahoo.com

    • Debasish Nayak
      Hi Rupom, For storing in the database using BLOB type it worked.But while fetching the data how can I open the word document containing the same data. For e.g,
      Message 2 of 6 , Jun 1, 2006
      • 0 Attachment
        Hi Rupom,

        For storing in the database using BLOB type it
        worked.But while fetching the data how can I open the
        word document containing the same data.

        For e.g,
        I am displaying:

        Title Name Document(Link)
        Chem xyz abc.doc

        Suppose above are 3 fields in my DB.I am fetching the
        datas from the DB where under document field I am
        storing the File name & in another field(suppose
        "Content") I am storing the content of the file.

        On clicking abc.doc link a word document should open
        containg the data at the time of uploading.

        Waiting for early response

        Thank You
        Debasish

        --- Rupom <rupom_315@...> wrote:

        >
        > Hi Debasish,
        > Create a BLOB type field in your table to store the
        > filedata along
        > with another fleld to store the filename(with
        > extension).
        >
        > In the time of display, grab that filedata from that
        > BLOB table field
        > and temporarily save it to a file with the same name
        > & extension
        > you stored. And then show the file.
        >
        > Thanks.
        >
        > Rupom
        >
        > Debasish Nayak <nayak_pinku1982@...> wrote:
        > Hi,
        >
        > In my project when a user will upload any file I
        > want to store it in the database(not in any folder)
        > &
        > display the same file to the user at the time of
        > fetching data.
        >
        > For example the user stored test.doc file while
        > uploading.At the time of viewing the user should
        > see
        > it in same ".doc" format.
        >
        > Please help me in the above matter.
        >
        > Thanks
        > Debasish
        >
        > Send instant messages to your online friends
        > http://in.messenger.yahoo.com
        >
        >
        >
        >
        >
        > -------------------------------------------
        > Keep Yourself Here and Enjoy PHPing.
        >
        >
        >
        > SPONSORED LINKS
        >
        > Computer store
        > Programming languages
        > Online computer store
        > Apple
        > computer store
        > Computer store business plan
        > Dell computer store
        >
        >
        > ---------------------------------
        > YAHOO! GROUPS LINKS
        >
        >
        > Visit your group "phpresource" on the web.
        >
        > To unsubscribe from this group, send an email
        > to:
        > phpresource-unsubscribe@yahoogroups.com
        >
        > Your use of Yahoo! Groups is subject to the
        > Yahoo! Terms of Service.
        >
        >
        > ---------------------------------
        >
        >
        >
        >
        >
        > http://www.rupom.info
        > http://www.rupom.tk
        >
        > Join phpResource Group And Enjoy PHPing...
        >
        > __________________________________________________
        > Do You Yahoo!?
        > Tired of spam? Yahoo! Mail has the best spam
        > protection around
        > http://mail.yahoo.com


        Send instant messages to your online friends
        http://in.messenger.yahoo.com

        Send instant messages to your online friends http://in.messenger.yahoo.com
      • Rupom
        Hi, In opening a doc file, Internet Explorer gives option to open the file. Firefox also gives same option. You have to do these things: 1. Add this line to
        Message 3 of 6 , Jun 3, 2006
        • 0 Attachment
          Hi,
          In opening a doc file, Internet Explorer gives option to open the file.
          Firefox also gives same option.

          You have to do these things:
          1. Add this line to your apache/httpd.conf
          -----------------------------------------------
          AddType application/x-doc .doc
          ----------------------------------------------
          2. Add appropriate header before outputting the filedata. Like this one:
          --------------------------------------------------------------
          header('Content-type:application/msword');
          readfile('my_doc_file.doc');
          --------------------------------------------------------------
          The first line is for MSWord. Other wordprocessor has their own options.

          It will help you.

          Regards,
          Rupom

          Debasish Nayak <nayak_pinku1982@...> wrote:
          Hi Rupom,

          For storing in the database using BLOB type it
          worked.But while fetching the data how can I open the
          word document containing the same data.

          For e.g,
          I am displaying:

          Title        Name       Document(Link)
          Chem         xyz         abc.doc

          Suppose above are 3 fields in my DB.I am fetching the
          datas from the DB where under document field I am
          storing the File name & in another field(suppose
          "Content") I am storing the content of the file.

          On clicking abc.doc link a word document should open
          containg the data at the time of uploading.

          Waiting for early response

          Thank You
          Debasish

          --- Rupom <rupom_315@...> wrote:

          >
          > Hi Debasish,
          > Create a BLOB type field in your table to store the
          > filedata along
          > with another fleld to store the filename(with
          > extension).
          >
          > In the time of display, grab that filedata from that
          > BLOB table field
          > and temporarily save it to a file with the same name
          > & extension
          > you stored. And then show the file.
          >
          > Thanks.
          >
          > Rupom   
          >
          > Debasish Nayak <nayak_pinku1982@...> wrote:
          >   Hi,

          >     In my project when a user will upload any file I
          >  want to store it in the database(not in any folder)
          > &
          >  display the same file to the user at the time of
          >  fetching data.

          >     For example the user stored test.doc file while
          >  uploading.At the time of viewing the user should
          > see
          >  it in same ".doc" format.

          >     Please help me in the above matter.

          >  Thanks
          >  Debasish

          >  Send instant messages to your online friends
          > http://in.messenger.yahoo.com


          >     
          >
          >  
          >  -------------------------------------------
          >  Keep Yourself Here and Enjoy PHPing.
          >
          >              
          >
          >         SPONSORED LINKS  
          >                                                   
          > Computer store                                     
          > Programming languages                              
          >        Online computer store                       
          >                                             Apple
          > computer store                                     
          > Computer store business plan                       
          >               Dell computer store                  
          >                                             
          >      
          > ---------------------------------
          >    YAHOO! GROUPS LINKS

          >    
          >     Visit your group "phpresource" on the web.
          >    
          >     To unsubscribe from this group, send an email
          > to:
          >  phpresource-unsubscribe@yahoogroups.com
          >    
          >     Your use of Yahoo! Groups is subject to the
          > Yahoo! Terms of Service.

          >    
          > ---------------------------------


          >     
          >
          >
          > http://www.rupom.info
          http://www.rupom.tk
          >  
          > Join phpResource Group And Enjoy PHPing...
          >
          > __________________________________________________
          > Do You Yahoo!?
          > Tired of spam?  Yahoo! Mail has the best spam
          > protection around
          > http://mail.yahoo.com


          Send instant messages to your online friends
          http://in.messenger.yahoo.com

          Send instant messages to your online friends http://in.messenger.yahoo.com






           
          Join phpResource Group And Enjoy PHPing...


          Talk is cheap. Use Yahoo! Messenger to make PC-to-Phone calls. Great rates starting at 1ยข/min.

        Your message has been successfully submitted and would be delivered to recipients shortly.