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

Reply

Join Date: Jun 2008
Posts: 9
Reputation: kwesiaryee is an unknown quantity at this point 
Solved Threads: 0
kwesiaryee kwesiaryee is offline Offline
Newbie Poster

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

 
0
  #1
Aug 27th, 2008

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.



  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>
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 213
Reputation: nikesh.yadav is an unknown quantity at this point 
Solved Threads: 17
nikesh.yadav's Avatar
nikesh.yadav nikesh.yadav is offline Offline
Posting Whiz in Training

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

 
0
  #2
Aug 27th, 2008
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
Help as an alias

I think programming is great................
Tour Travel weblink by me and about Tour ,
Go To My Home Page and I m in Webdevelopment.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC