Pulling Images out from directory using PHP and mySQL

Reply

Join Date: Jul 2009
Posts: 20
Reputation: papermusic is an unknown quantity at this point 
Solved Threads: 0
papermusic papermusic is offline Offline
Newbie Poster

Pulling Images out from directory using PHP and mySQL

 
0
  #1
Jul 28th, 2009
  1.  
  2. <?php
  3.  
  4. include 'dbc.php';
  5.  
  6. $query = "SELECT * FROM em.tutor";
  7. $result = mysql_query($query);
  8.  
  9. while($row = mysql_fetch_array($result, MYSQL_NUM))
  10. {
  11. echo "Name :{$row[0]} <br>" .
  12. "Subject : {$row[1]} <br>" .
  13. "Message : {$row[2]} <br><br>".
  14. "Message1 : {$row[3]} <br><br>".
  15. "Message2 : {$row[4]} <br><br>".
  16. "Message3 : {$row[5]} <br><br>".
  17. "Message : {$row[6]} <br><br>".
  18. "Message : {$row[7]} <br><br>".
  19. "Message : {$row[8]} <br><br>".
  20. "Message : {$row[9]} <br><br>".
  21. "Message : {$row[10]} <br><br>".
  22. "Message : {$row[11]} <br><br>".
  23. "Message : {$row[12]} <br><br>".
  24. "Message : {$row[13]} <br><br>".
  25. "Message : {$row[14]} <br><br>".
  26. "Message : {$row[15]} <br><br>".
  27. "Message : {$row[16]} <br><br>".
  28.  
  29.  
  30. "<img src=/em/tutor/images/".
  31.  
  32.  
  33. "<br>___________________________________________________________<BR /><BR />";
  34. }
  35.  
  36.  
  37. ?>


hi, i need some help on displaying images on my page listing.

i dun understand why the image doesn't display with the page results, there's no error in the code.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 596
Reputation: buddylee17 has a spectacular aura about buddylee17 has a spectacular aura about 
Solved Threads: 125
buddylee17's Avatar
buddylee17 buddylee17 is offline Offline
Posting Pro

Re: Pulling Images out from directory using PHP and mySQL

 
1
  #2
Jul 28th, 2009
You haven't specified an image: "<img src=/em/tutor/images/". only specifies the folder that the image should be located.
Lost time is never found again.
- Benjamin Franklin
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 20
Reputation: papermusic is an unknown quantity at this point 
Solved Threads: 0
papermusic papermusic is offline Offline
Newbie Poster

Re: Pulling Images out from directory using PHP and mySQL

 
0
  #3
Jul 29th, 2009
how can i move the images using PHP and mySQL to my apache web directory? initially i was trying to upload the image directly into mysql but it doesnt works.

i am stucked and got timeout error which i believe is to have come from this part of the code "move_uploaded_file". help please anyone ?





  1. <?php
  2. session_start();
  3. error_reporting (E_ALL ^ E_NOTICE);
  4.  
  5.  
  6.  
  7. include ('dbc.php');
  8.  
  9. if ($_POST['Submit'] == 'Complete Registration')
  10.  
  11. //validation
  12. {
  13.  
  14. if (strlen($_POST['email']) < 5)
  15. //die string length shorter than 5
  16. {
  17. die ("Incorrect email. Please enter valid email address..");
  18. }
  19.  
  20.  
  21. if (strcmp($_POST['pass1'],$_POST['pass2']) || empty($_POST['pass1']) )
  22. {
  23. //die ("Password does not match");
  24. die("ERROR: Password does not match or empty..");
  25. }
  26.  
  27.  
  28. if (strcmp(md5($_POST['user_code']),$_SESSION['ckey']))
  29. {
  30. die("Invalid code entered. Please enter the correct code as shown in the Image");
  31. }
  32.  
  33.  
  34.  
  35. //check if username exist
  36. $rs_duplicates = mysql_query("select id from users where user_email='$_POST[email]'");
  37. $duplicates = mysql_num_rows($rs_duplicates);
  38.  
  39. if ($duplicates > 0)
  40.  
  41. {
  42. //die ("ERROR: User account already exists.");
  43. header("Location: register.php?msg=ERROR: User account already exists..");
  44. exit();
  45. }
  46.  
  47. $target = "images/";
  48. $target = $target . basename( $_FILES['photo']['name']);
  49. $pic=($_FILES['photo']['name']);
  50.  
  51. /*
  52.  
  53. $imgtype =$_REQUEST['imgtype'];
  54. $imgdata =$_REQUEST['imgdata'];
  55.  
  56. $hndl =fopen($_REQUEST["imgfile"],"r");
  57. $isize =sizeof($_REQUEST["imgfile"]);
  58.  
  59. $imgdata="";
  60. while(!feof($hndl)){
  61. $imgdata.=fread($hndl,$isize);
  62. };
  63.  
  64. $imgdata=addslashes($imgdata);
  65.  
  66.  
  67. $name_box = $_REQUEST["name_box"];
  68. while (list ($key_check,$val_check) = @each ($name_box))
  69. {
  70. $value_check .= $val_check.",";
  71. }
  72.  
  73. $all_value_check = substr($value_check, 0, -1);
  74.  
  75. echo $all_value_check;
  76.  
  77.  
  78. */
  79.  
  80.  
  81.  
  82. $md5pass = md5($_POST['pass2']);
  83. $activ_code = rand(1000,9999);
  84. $server = $_SERVER['HTTP_HOST'];
  85. $host = ereg_replace('www.','',$server);
  86.  
  87.  
  88.  
  89. mysql_query("INSERT INTO tutor
  90. (`user_email`,`user_pwd`,`joined`,`activation_code`,`full_name`,`imgdata`,`gender`,`race`,`commitment`,`tutoring_location`,`current_location`,`qualification`,`imgtype`)
  91. VALUES
  92. ('$_POST[email]','$md5pass',now(),'$activ_code','$_POST[full_name]','$_POST[imgtype]','$_POST[gender]','$_POST[race]','$_POST[commit]','$_POST[loc]','$_POST[cloc]','$_POST[qual]','$pic')") or die(mysql_error());
  93.  
  94.  
  95. if(move_uploaded_file($_FILES['photo']['tmp_name'], $target))
  96. {
  97.  
  98. //Tells you if its all ok
  99. echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory";
  100. }
  101. else {
  102.  
  103. //Gives and error if its not
  104. echo "Sorry, there was a problem uploading your file.";
  105. }
  106.  
  107.  
  108.  
  109. $message =
  110. "Thank you for registering an account with $server. Here are the login details...\n\n
  111. User Email: $_POST[email] \n
  112. Password: $_POST[pass2] \n
  113. Activation Code: $activ_code \n
  114. ____________________________________________
  115. *** ACTIVATION LINK ***** \n
  116. Activation Link: http://$server/em/login/activate.php?usr=$_POST[email]&code=$activ_code \n\n
  117. _____________________________________________
  118. Thank you. This is an automated response. PLEASE DO NOT REPLY.
  119. ";
  120.  
  121.  
  122. mail($_POST['email'] , "Login Activation", $message,
  123. "From: \"Auto-Response\" <notifications@$host>\r\n" .
  124. "X-Mailer: PHP/" . phpversion());
  125. unset($_SESSION['ckey']);
  126. echo("Registration Successful! An activation code has been sent to your email address with an activation link...");
  127.  
  128. exit;
  129. }
  130.  
  131. ?>
  132.  
  133. <link href="styles.css" rel="stylesheet" type="text/css">
  134.  
  135. <?php if (isset($_GET['msg'])) { echo "<div class=\"msg\"> $_GET[msg] </div>"; } ?>
  136.  
  137.  
  138.  
  139. <table align=center width="80%" border="0" cellpadding="3" cellspacing="10">
  140.  
  141. <td width=30% bgcolor="e5ecf9" class="forumposts"><form name="form1" method="post" action="register.php" style="padding:5px;">
  142. <tr>
  143. <th colspan=3 bgcolor="d5e8f9" class="mnuheader"><strong><font size="5">Music Instructor Registration Form</font></strong></th>
  144.  
  145. </tr>
  146.  
  147.  
  148.  
  149. <tr>
  150.  
  151. Photo: <input type="file" name="photo"><br>
  152.  
  153.  
  154.  
  155. </tr>
  156.  
  157.  
  158. <tr>
  159. <td align=right>Name:</td>
  160. <td colspan=2><input name="full_name" type="text" id="full_name"> &nbsp&nbsp&nbsp&nbsp&nbsp Ex. Stanley Tan
  161.  
  162.  
  163. </tr>
  164.  
  165. <tr>
  166.  
  167. <td align=right>Email: </td>
  168. <td><input name="email" type="text" id="email"> </td>
  169.  
  170. </tr>
  171.  
  172. <tr>
  173. <td align=right>Password:</td>
  174. <td><input name="pass1" type="password" id="pass1"> Min 8 chars &nbsp&nbsp&nbsp&nbsp&nbsp
  175.  
  176. </tr>
  177.  
  178. <tr>
  179. <td align=right>Retype Password:</td>
  180. <td><input name="pass2" type="password" id="pass2"></td>
  181. </tr>
  182.  
  183. //blah blah..........more similar code removed.
  184.  
  185.  
  186. <tr>
  187. <td align=right>Enter code on right:</td>
  188. <td><input name="user_code" type="text" size="10">&nbsp&nbsp<img src="pngimg.php" align="middle">&nbsp; </td>
  189. </tr>
  190.  
  191.  
  192.  
  193. <tr>
  194. <td colspan=3><input type="submit" name="Submit" value="Complete Registration" style="height: 35px; width: 100%"></td>
  195. </tr>
  196.  
  197.  
  198. </table>
  199.  
  200. </body>
  201. </html>
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 20
Reputation: papermusic is an unknown quantity at this point 
Solved Threads: 0
papermusic papermusic is offline Offline
Newbie Poster

Re: Pulling Images out from directory using PHP and mySQL

 
0
  #4
Jul 30th, 2009
The problem i am having is that when i insert the image to the database, the blob image stay at 9kb no matter what filesize i am using...when i try to display the image from MySQL database, nothing comes out....

anyone can help me pls ?


  1.  
  2. <?php
  3.  
  4. session_start();
  5. error_reporting (E_ALL ^ E_NOTICE);
  6.  
  7. include ('dbc.php');
  8.  
  9. if ($_POST['Submit'] == 'Complete Registration')
  10.  
  11. //validation
  12. {
  13.  
  14. if (strlen($_POST['email']) < 5)
  15. //die string length shorter than 5
  16. {
  17. die ("Incorrect email. Please enter valid email address..");
  18. }
  19.  
  20.  
  21. if (strcmp($_POST['pass1'],$_POST['pass2']) || empty($_POST['pass1']) )
  22. {
  23. //die ("Password does not match");
  24. die("ERROR: Password does not match or empty..");
  25. }
  26.  
  27.  
  28. if (strcmp(md5($_POST['user_code']),$_SESSION['ckey']))
  29. {
  30. die("Invalid code entered. Please enter the correct code as shown in the Image");
  31. }
  32.  
  33.  
  34.  
  35. //check if username exist
  36. $rs_duplicates = mysql_query("select id from users where user_email='$_POST[email]'");
  37. $duplicates = mysql_num_rows($rs_duplicates);
  38.  
  39. if ($duplicates > 0)
  40.  
  41. {
  42. //die ("ERROR: User account already exists.");
  43. header("Location: register.php?msg=ERROR: User account already exists..");
  44. exit();
  45. }
  46.  
  47. $imgtype =$_REQUEST['imgtype'];
  48. $imgdata =$_REQUEST['imgdata'];
  49.  
  50. $hndl =fopen($_REQUEST["imgfile"],"r");
  51. $isize =sizeof($_REQUEST["imgfile"]);
  52.  
  53. $imgdata="";
  54. while(!feof($hndl)){
  55. $imgdata.=fread($hndl,$isize);
  56. };
  57.  
  58. $imgdata=addslashes($imgdata);
  59.  
  60.  
  61. $name_box = $_REQUEST["name_box"];
  62. while (list ($key_check,$val_check) = @each ($name_box))
  63. {
  64. $value_check .= $val_check.",";
  65. }
  66.  
  67. $all_value_check = substr($value_check, 0, -1);
  68.  
  69. echo $all_value_check;
  70.  
  71.  
  72.  
  73.  
  74. $md5pass = md5($_POST['pass2']);
  75. $activ_code = rand(1000,9999);
  76. $server = $_SERVER['HTTP_HOST'];
  77. $host = ereg_replace('www.','',$server);
  78.  
  79.  
  80. mysql_query("INSERT INTO tutor
  81. (`user_email`,`user_pwd`,`joined`,`activation_code`,`full_name`,`imgdata`,`gender`,`race`,`commitment`,`tutoring_location`,`current_location`,`qualification`,`test`,`imgtype`)
  82. VALUES
  83. ('$_POST[email]','$md5pass',now(),'$activ_code','$_POST[full_name]','$_POST[imgtype]','$_POST[gender]','$_POST[race]','$_POST[commit]','$_POST[loc]','$_POST[cloc]','$_POST[qual]','$all_value_check','$_POST[imgtype]')") or die(mysql_error());
  84.  
  85. $message =
  86. "Thank you for registering an account with $server. Here are the login details...\n\n
  87. User Email: $_POST[email] \n
  88. Password: $_POST[pass2] \n
  89. Activation Code: $activ_code \n
  90. ____________________________________________
  91. *** ACTIVATION LINK ***** \n
  92. Activation Link: http://$server/em/login/activate.php?usr=$_POST[email]&code=$activ_code \n\n
  93. _____________________________________________
  94. Thank you. This is an automated response. PLEASE DO NOT REPLY.
  95. ";
  96.  
  97.  
  98. mail($_POST['email'] , "Login Activation", $message,
  99. "From: \"Auto-Response\" <notifications@$host>\r\n" .
  100. "X-Mailer: PHP/" . phpversion());
  101. unset($_SESSION['ckey']);
  102. echo("Registration Successful! An activation code has been sent to your email address with an activation link...");
  103.  
  104. exit;
  105. }
  106.  
  107. ?>
  108.  
  109. <link href="styles.css" rel="stylesheet" type="text/css">
  110.  
  111. <?php if (isset($_GET['msg'])) { echo "<div class=\"msg\"> $_GET[msg] </div>"; } ?>
  112.  
  113.  
  114.  
  115. <table align=center width="80%" border="0" cellpadding="3" cellspacing="10">
  116.  
  117. <td width=30% bgcolor="e5ecf9" class="forumposts"><form name="form1" method="post" action="register.php" style="padding:5px;">
  118. <tr>
  119. <th colspan=3 bgcolor="d5e8f9" class="mnuheader"><strong><font size="5">Music Instructor Registration Form</font></strong></th>
  120.  
  121. </tr>
  122.  
  123.  
  124.  
  125. <tr>
  126.  
  127. <td align=right>Upload Your Photo:<br /> (Filesize must not exceed 500kb)</td>
  128. <td><input type="file" id='imgfile' name="imgfile">&nbsp&nbsp&nbsp&nbsp&nbsp
  129. <select name="imgtype">
  130. <option value="image/gif">GIF</option>
  131. <option value="image/jpeg">JPEG</option></select></td>
  132.  
  133. </tr>
  134.  
  135.  
  136. <tr>
  137. <td align=right>Name:</td>
  138. <td colspan=2><input name="full_name" type="text" id="full_name"> &nbsp&nbsp&nbsp&nbsp&nbsp Ex. Stanley Tan
  139.  
  140.  
  141. </tr>
  142.  
  143. <tr>
  144.  
  145. <td align=right>Email: </td>
  146. <td><input name="email" type="text" id="email"> </td>
  147.  
  148. </tr>
  149.  
  150. <tr>
  151. <td align=right>Password:</td>
  152. <td><input name="pass1" type="password" id="pass1"> Min 8 chars &nbsp&nbsp&nbsp&nbsp&nbsp
  153.  
  154. </tr>
  155.  
  156. <tr>
  157. <td align=right>Retype Password:</td>
  158. <td><input name="pass2" type="password" id="pass2"></td>
  159. </tr>
  160.  
  161. // all the get info from user stuffs here ommitted.
  162.  
  163.  
  164. <tr>
  165. <td colspan=3><input type="submit" name="Submit" value="Complete Registration" style="height: 35px; width: 100%"></td>
  166. </tr>
  167.  
  168.  
  169. </table>
  170.  
  171. </body>
  172. </html>
Last edited by papermusic; Jul 30th, 2009 at 2:40 am. Reason: error
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 596
Reputation: buddylee17 has a spectacular aura about buddylee17 has a spectacular aura about 
Solved Threads: 125
buddylee17's Avatar
buddylee17 buddylee17 is offline Offline
Posting Pro

Re: Pulling Images out from directory using PHP and mySQL

 
0
  #5
Jul 31st, 2009
Don't store images in a database. Is it a picturebase or a database???
Seriously, store the path to the pic in the db, store the pic on the server. The db is designed to store data. The server is designed to store everything else. Don't use a water jug to store gasoline. Put it in a gas jug.
If your' script is decent, then you can use the path to pull the pic. If not, you should probably go study @ www.php.net.
Lost time is never found again.
- Benjamin Franklin
Reply With Quote Quick reply to this message  
Reply

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



Similar Threads
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