MySQL
  Home arrow MySQL arrow Page 3 - Blobbing Data With PHP and MySQL
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
MYSQL

Blobbing Data With PHP and MySQL
By: Mitchell Harper
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 276
    2002-02-05

    Table of Contents:
  • Blobbing Data With PHP and MySQL
  • Creating the database
  • Adding blobs to the database
  • The grabfile.php script
  • Displaying the files
  • The downloadfile.php script
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Blobbing Data With PHP and MySQL - Adding blobs to the database


    (Page 3 of 7 )

    Now that we've got our table structure sorted out, let's use a simple PHP script to capture files from a users computer and store them in our database. Create a new PHP script named getfiles.php and save it into a directory that your web server can process. Enter the following code into getfiles.php:

    <html>

    <head>

    <title> Upload a File </title>

    </head>

    <body bgcolor="#FFFFFF">

    <form enctype="multipart/form-data" name="frmUploadFile" action="grabfile.php" method="post">

    <a href="http://www.devarticles.com">

    <img border="0" src="http://www.devarticles.com/dlogo.gif">

    </a>

    <table border="0" cellpadding="0" cellspacing="0" bordercolor="#111111" width="100%">

    <tr>

    <td width="100%" bgcolor="#FF9900" height="22" colspan="2">

    <p style="margin-left: 10"><b><font face="Verdana" size="2" color="#FFFFFF">

    Upload a File</font></b></td>

    </tr>

    <tr>

    <td width="100%" bgcolor="#FFE3BB" colspan="2">

    <p style="margin-left: 10; margin-right: 10"><font face="Verdana" size="2">

    <br>Please select a file from your local computer to upload to our web server

    for saving in our database. This file can be of any type you like. Once you

    have chosen a file, please click on the &quot;Upload this file&quot; button below.&nbsp;

    &nbsp;<br>&nbsp;</font></td>

    </tr>

    <tr>

    <td width="15%" bgcolor="#FFE3BB">

    <p style="margin-left: 10"><font face="Verdana" size="2">

    File Description:</font></td>

    <td width="85%" bgcolor="#FFE3BB">

    <input type="text" name="strDesc" size="20" maxlength="50"></td>

    </tr>

    <tr>

    <td width="15%" bgcolor="#FFE3BB">

    <p style="margin-left: 10"><font face="Verdana" size="2">File Location:</font></td>

    <td width="85%" bgcolor="#FFE3BB">

    <font face="Verdana" size="2">

    <input type="file" name="fileUpload" size="20"></font></td>

    </tr>

    <tr>

    <td width="33%" bgcolor="#FFE3BB">

    <p style="margin-left: 10"><font face="Verdana" size="2">

    <br>

    <br>

    &nbsp;</font></td>

    <td width="67%" bgcolor="#FFE3BB">

    <font face="Verdana" size="2">

    <input type="submit" value="Upload this file" name="cmdSubmit"></font></td>

    </tr>

    </table>

    </form>

    </body>

    </html>


    In the page above, we've created a HTML form that allows us to send files to the server. It allows the user to choose a file to upload, and to also enter a description for that file. The only difference between the form above and any other HTML form, is that the enctype attribute of our form is set to "multipart/form-data":

    <form enctype="multipart/form-data" name="frmUploadFile" action="grabfile.php" method="post">

    This tells the browser that we may be sending files from the client's machine to the server, so it should be ready to prepare the headers and stream the files to the server, amongst other things. Our getfile.php page looks like this:

    Our getfile.php page in the browser

    Our form will post its results to grabfile.php, which will be responsible for adding the file to the database as a BLOB. Let's create that file now.

    More MySQL Articles
    More By Mitchell Harper


       · AM devolping a website in which am using PHP and MYSQL, and here any member can...
       · this will not transfer the variable $_FILE. After a bit of research i found if you...
       · Not seeing this "Support Material" I keep seeing.. Can someone direct me to it?
       · I am on Apache 2.0 server. When I enter the grabfile page I do not see how the...
     

    MYSQL ARTICLES

    - MySQL and BLOBs
    - Two Lessons in ASP and MySQL
    - Lord Of The Strings Part 2
    - Lord Of The Strings Part 1
    - Importing Data into MySQL with Navicat
    - Building a Sustainable Web Site
    - Creating An Online Photo Album with PHP and ...
    - Creating An Online Photo Album with PHP and ...
    - PhpED 3.2 – More Features Than You Can Poke ...
    - Creating An Online Photo Album with PHP and ...
    - Creating An Online Photo Album with PHP and ...
    - Security and Sessions in PHP
    - Setup Your Personal Reminder System Using PHP
    - Create a IP-Country Database Using PERL and ...
    - Developing a Dynamic Document Search in PHP ...







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
    Stay green...Green IT