|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
Blobbing data with MYSQl and PHP
hi,
i tried to incoporate a script to my site as per the directions in the article by Mitchell Harper at URL everything seems to be fine except, i can't view my files other than the HTML files. showfiles.php is showing the type of files exactly. but when i click on download.php i'm getting a blank page for all file types other than .html files. where may be the problem? plz help me |
|
#2
|
|||
|
|||
|
hey jackeapen,
welcome to the devarticles forums!! cold you post the code which you've got so far? then we can determine the problem (hopefully!! ) |
|
#3
|
|||
|
|||
|
hi,
here r the codes which i use. plz try to find out the problem ##### upload.php __________________ html> <head> <title> Upload a File </title> </head> <body bgcolor="#FFFFFF"> <form enctype="multipart/form-data" name="frmUploadFile" action="grabfile.php" method="post"> <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 "Upload this file" button below. <br> </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> </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> ######grabfile.php <?php // GrabFile.php: Takes the details // of the new file posted as part // of the form and adds it to the // myBlobs table of our myFiles DB. global $strDesc; global $fileUpload; global $fileUpload_name; global $fileUpload_size; global $fileUpload_type; // Make sure both a description and // file have been entered if(empty($strDesc) || $fileUpload == "none") die("You must enter both a description and file"); // Database connection variables $dbServer = "localhost"; $dbDatabase = "openbiblio"; $dbUser = "admin"; $dbPass = "admin"; $fileHandle = fopen($fileUpload, "r"); $fileContent = fread($fileHandle, $fileUpload_size); $fileContent = addslashes($fileContent); $sConn = mysql_connect($dbServer, $dbUser, $dbPass) or die("Couldn't connect to database server"); $dConn = mysql_select_db($dbDatabase, $sConn) or die("Couldn't connect to database $dbDatabase"); $dbQuery = "INSERT INTO myBlobs VALUES "; $dbQuery .= "(0, '$strDesc', '$fileContent', '$fileUpload_type')"; mysql_query($dbQuery) or die("Couldn't add file to database"); echo "<h1>File Uploaded</h1>"; echo "The details of the uploaded file are shown below:<br><br>"; echo "<b>File name:</b> $fileUpload_name <br>"; echo "<b>File type:</b> $fileUpload_type <br>"; echo "<b>File size:</b> $fileUpload_size <br>"; echo "<b>Uploaded to:</b> $fileUpload <br><br>"; echo "<a href='upload.php'>Add Another File</a>"; #####showfiles.php <? $dbServer = "localhost"; $dbDatabase = "openbiblio"; $dbUser = "admin"; $dbPass = "admin"; $sConn = mysql_connect($dbServer, $dbUser, $dbPass) or die("Couldn't connect to database server"); $dConn = mysql_select_db($dbDatabase, $sConn) or die("Couldn't connect to database $dbDatabase"); $dbQuery = "SELECT blobId, blobTitle, blobType "; $dbQuery .= "FROM myBlobs "; $dbQuery .= "ORDER BY blobTitle ASC"; $result = mysql_query($dbQuery) or die("Couldn't get file list"); ?> <table border="1" cellpadding="0" cellspacing="0" bordercolor="#111111" width="100%"> <tr> <td width="34%" bgcolor="#FF9900" height="21"> <p style="margin-left: 10"><b><font size="2" face="Verdana" color="#FFFFFF"> Description</font></b></td> <td width="33%" bgcolor="#FF9900" height="21"> <p style="margin-left: 10"><b><font face="Verdana" size="2" color="#FFFFFF"> Type</font></b></td> <td width="33%" bgcolor="#FF9900" height="21"> <p style="margin-left: 10"><b><font face="Verdana" size="2" color="#FFFFFF"> File</font></b></td> </tr> <?php while($row = mysql_fetch_array($result)) { ?> <tr> <td width="34%" bgcolor="#FFDCA8" height="21"> <p style="margin-left: 10; margin-right: 10"> <font face="Verdana" size="1"> <?php echo $row["blobTitle"]; ?> </font> </td> <td width="33%" bgcolor="#FFDCA8" height="21"> <p style="margin-left: 10"> <font face="Verdana" size="1"> <?php echo $row["blobType"]; ?> </font> </td> <td width="33%" bgcolor="#FFDCA8" height="21"> <p style="margin-left: 10"><font face="Verdana" size="1"> <a href="downloadfile.php?blobId=<?php echo $row["blobId"]; ?>"> Download now </a></font> </td> </tr> <?php } echo "</table>"; ?> <a href="downloadfile.php?blobId=<?php echo $row["blobId"]; ?>"> Download now </a> #####download.php <?php global $blobId; if(!is_numeric($blobId)) die("Invalid blobId specified"); // Database connection variables $dbServer = "localhost"; $dbDatabase = "openbiblio"; $dbUser = "admin"; $dbPass = "admin"; $sConn = mysql_connect($dbServer, $dbUser, $dbPass) or die("Couldn't connect to database server"); $dConn = mysql_select_db($dbDatabase, $sConn) or die("Couldn't connect to database $dbDatabase"); $dbQuery = "SELECT blobType, blobData "; $dbQuery .= "FROM myBlobs "; $dbQuery .= "WHERE blobId = $blobId"; $result = mysql_query($dbQuery) or die("Couldn't get file list"); if(mysql_num_rows($result) == 1) { $fileType = @mysql_result($result, 0, "blobType"); $fileContent = @mysql_result($result, 0, "blobData"); header("Cache-Control: private"); header("Content-type: $fileType"); echo $fileContent; } else { echo "Record doesn't exist."; } ?> |
|
#4
|
|||
|
|||
|
jackeapen,
What version of PHP are you running? Also, do you receive any error messages, or is it simply the blank pages?
__________________
____________________________________________ Developer Shed Weekly Writer | DevArticles Forum Moderator Build Your Own KlipFolio Klip With PHP FrankManno.com - Under Construction Design Interactive Group - Under Construction |
|
#5
|
|||
|
|||
|
hi,
i'm using PHP 4.3.0 on Windows 98. MySQL 3.23.47 i'm not receiving any error message. simply a blank page Jack |
![]() |
| Viewing: Dev Articles Community Forums > Databases > MySQL Development > Blobbing data with MYSQl and PHP |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|