943,800 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 911
  • PHP RSS
Aug 27th, 2008
0

Please I need help on image upload to mysql and display in browser

Expand Post »

Hi,
I am terribly stuck with this code. It is suposed to upload my images to the mysql database with the foreign key(property_id). At first it worked, then later started giving serious errors where the web page could not load. I am lost. Can any one help me, solve this...please . Below is the code snippet.



php Syntax (Toggle Plain Text)
  1. <form method="post" enctype="multipart/form-data">
  2. <table width="350" border="0" cellpadding="1" cellspacing="1" class="box">
  3. <tr>
  4. <td class="formText">Property Description:&nbsp;&nbsp;
  5. <select name="userfile">
  6. <?php
  7. do {
  8. ?>
  9. <option value="<?php echo $row_cust['property_id']?>">
  10. <?php echo $row_cust['description']?>
  11. </option>
  12. <?php
  13. } while ($row_cust = mysql_fetch_assoc($cust));
  14. $rows = mysql_num_rows($cust);
  15. if($rows > 0) {
  16. mysql_data_seek($cust, 0);
  17. $row_cust = mysql_fetch_assoc($cust);
  18. }
  19. ?>
  20. </select></td>
  21. <td width="125"> </td>
  22. </tr>
  23. <tr>
  24. <td>&nbsp;</td>
  25. <td></td>
  26. </tr>
  27. <tr>
  28. <td width="218">
  29. <input type="hidden" name="MAX_FILE_SIZE" value="2000000">
  30. <input name="userfile" type="file" id="userfile">
  31. </td>
  32. <td width="125"><input name="upload" type="submit" class="box" id="upload" value=" Upload "></td>
  33. </tr>
  34. <tr>
  35. <td class="text" colspan="2">
  36. <?php
  37. if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0)
  38. {
  39. $fileName = $_FILES['userfile']['name'];
  40. $tmpName = $_FILES['userfile']['tmp_name'];
  41. $fileSize = $_FILES['userfile']['size'];
  42. $fileType = $_FILES['userfile']['type'];
  43. $pid = $_POST['userfile']['property_id'];
  44.  
  45. $fp = fopen($tmpName, 'r');
  46. $content = fread($fp, filesize($tmpName));
  47. $content = addslashes($content);
  48. fclose($fp);
  49.  
  50. if(!get_magic_quotes_gpc())
  51. {
  52. $fileName = addslashes($fileName);
  53. }
  54.  
  55. include 'library/config.php';
  56. include 'library/opendb.php';
  57.  
  58. $query = "INSERT INTO upload (property_id, name, size, type, content ) ".
  59. "VALUES ('$pid', '$fileName', '$fileSize', '$fileType', '$content')";
  60.  
  61. mysql_query($query) or die('Error, query failed');
  62.  
  63. include 'library/closedb.php';
  64.  
  65. echo "<br>$fileName has been uploaded Successfully <br>";
  66. }
  67. ?>
  68. </td>
  69. </tr>
  70. <tr>
  71. <td class="text" colspan="2"><a href="submit_thanks.php">Continue</a>, if done with image uploads.</td>
  72. </tr>
  73. <tr>
  74. <td colspan="2">&nbsp;</td>
  75. </tr>
  76. </table>
  77. </form>
Reputation Points: 10
Solved Threads: 0
Newbie Poster
kwesiaryee is offline Offline
11 posts
since Jun 2008
Aug 27th, 2008
0

Re: Please I need help on image upload to mysql and display in browser

read this article easy and full of code (one secret thing is that i make my first image upload module from the same code)

url is
http://www.wellho.net/solutions/php-...-retreive.html
Reputation Points: 15
Solved Threads: 21
Posting Whiz in Training
nikesh.yadav is offline Offline
219 posts
since Feb 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Newbie email error
Next Thread in PHP Forum Timeline: Socket programming





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC