Connecting Tech Pros Worldwide Forums | Help | Site Map

pool mysql files

Newbie
 
Join Date: Feb 2008
Posts: 22
#1: Jan 5 '09
i have this script that works very well. Basically it allows the user to attach a scanned pdf file of shipping forms and attach to the form.

Expand|Select|Wrap|Line Numbers
  1. <?
  2. include_once("format.php");
  3. echo $format;
  4.  
  5. ?>
  6. </div>
  7.  
  8. <div id="main"> <a name="TemplateInfo"></a>
  9.     <h1>Add Shipment Tracking</h1>
  10.  
  11. <form method="post" enctype="multipart/form-data">
  12. <table width="350" border="0" cellpadding="1" cellspacing="1" class="box">
  13. <tr> 
  14. <td width="246">
  15.  
  16. <b>Description:</b>
  17. <tr>
  18. <td>
  19. <input type='textarea' name='description' value='' size='50%'>
  20. <br />
  21.  
  22.  
  23. <b>Send/Receive:</b>
  24. <select name='send' value=''>
  25. <option selected value=''>
  26. <option>Sent
  27. <option>Received
  28. </select>
  29.  
  30. <b>Carrier:</b>
  31. <select name='carrier' value=''>
  32. <option selected value=''>
  33. <option>UPS
  34. <option>FEDEX
  35. <option>DHL
  36. <option>Sonic Air
  37. <option>Other
  38. </select><br /><br />
  39.  
  40.  
  41.  
  42.  
  43. <tr>
  44. <td colspan='1'>
  45. <b>Tracking Numbers:</b><br />
  46. <textarea name='tracking' rows='6' value='' wrap='hard'>
  47. <? echo $_POST['tracking'];?>
  48. </textarea>
  49. </td></tr><br />
  50.  
  51. <b>Upload Document:</b><br />
  52. <input type="hidden" name="MAX_FILE_SIZE" value="20000000">
  53. <input name="userfile" type="file" id="userfile"> 
  54. <td width="80"><input name="upload" type="submit" class="box" id="upload" value=" Upload "></td>
  55. </td>
  56.  
  57. </table>
  58. </form>
  59.  
  60. <?
  61. include_once('sql_connect.php');
  62.  
  63. ?>
  64.  
  65. <?
  66.  
  67. if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0)
  68. {
  69.  
  70.  
  71. $description = $_POST['description'];
  72. $tracking = $_POST['tracking'];
  73. $carrier = $_POST['carrier'];
  74. $send = $_POST['send'];
  75.  
  76. $fileName = $_FILES['userfile']['name'];
  77. $tmpName  = $_FILES['userfile']['tmp_name'];
  78. $fileSize = $_FILES['userfile']['size'];
  79. $fileType = $_FILES['userfile']['type'];
  80.  
  81.  
  82. $fp      = fopen($tmpName, 'r');
  83. $content = fread($fp, filesize($tmpName));
  84. $content = addslashes($content);
  85. fclose($fp);
  86.  
  87. if(!get_magic_quotes_gpc())
  88. {
  89.     $fileName = addslashes($fileName);
  90. }
  91.  
  92.  
  93. $query = "INSERT INTO ship_table (name, size, type, content1, description, tracking, carrier, send ) ".
  94. "VALUES ('$fileName', '$fileSize', '$fileType', '$content1', '$description', '$tracking', '$carrier', '$send')";
  95.  
  96. mysql_query($query) or die('Error, query failed'); 
  97.  
  98.  
  99. echo "<br>File $fileName uploaded<br>";
  100.  
  101. ?>
  102.  
Now here is the problem. How do I pull the file from the table from a search form. I have a simple little search form
Expand|Select|Wrap|Line Numbers
  1.  
  2. <?
  3. $content = $content. "
  4. <form method='post' action='search_tracking_submit.php'>
  5. <b>Track Shipment:</b> <br />
  6. <input type='text' name='search'><br />
  7. <input type='submit' name='submit_search' value='SEARCH!!'><br />
  8. </form>";
  9.  
  10. echo "<div id='content'>"
  11. .$content
  12. ."</div>";
  13.  
  14.  
  15. ?>
  16.  
the end result looks like this
Expand|Select|Wrap|Line Numbers
  1. <?
  2. include_once("./sql_connect.php");
  3.  
  4.  
  5.  
  6.  
  7.  
  8. $search = $_POST['search'];
  9. $gettracking = "SELECT * 
  10. FROM ship_table 
  11. WHERE description LIKE '%$search%'
  12. OR send LIKE '%$search%'
  13. OR carrier LIKE '%$search%'
  14. OR tracking LIKE '%$search%' 
  15. ORDER BY id ASC";
  16. $gettrackingResult = mysql_query($gettracking);
  17.  
  18. while (list($id, $description, $send, $carrier, $tracking, $time_stamp) = mysql_fetch_row($gettrackingResult))
  19. {
  20.  
  21. $content = $content. 
  22. "<b>ID #: </b>$id</a> <br />\n";
  23.  
  24.  
  25. $content = $content. 
  26. "<b>Description: </b>$description</a> <br />\n";
  27.  
  28. $content = $content. 
  29. "<b>Status: </b>$send</a> <br />\n";
  30.  
  31. $content = $content. 
  32. "<b>Carrier: </b>$carrier</a> <br />\n";
  33.  
  34. $content = $content. 
  35. "<b>Tracking: <br /></b>$tracking</a> <br />\n";
  36.  
  37. $content = $content. 
  38. "<b>Time: </b>$time_stamp</a> <br /><br />\n";
  39.  
  40.  
  41. }
  42.  
  43. echo "<div id='content'>"
  44. .$content
  45. ."</div>";
  46. ?>
  47.  
how do I add to content something like

File : file.name <---- this being a link to download the file

Atli's Avatar
Moderator
 
Join Date: Nov 2006
Location: Iceland
Posts: 3,751
#2: Jan 5 '09

re: pool mysql files


Hi.

You might find this article helpful:
Uploading files into a MySQL database using PHP
Reply