July 22, 200818 yr hi again been experimenting with php and mysql again i now have a image stored in a BLOB (type) any ides of how to retrive it so i can display it on the screen screen thank you <?php $IP=$_SERVER["REMOTE_ADDR"]; include "connect.php"; //connection string print "<link rel='stylesheet' href='style.css' type='text/css'>"; print "<table class='maintables'>"; print "<tr class='headline'><td>Sell an Item</td></tr>"; print "<tr class='maintables'><td>"; if(isset($_POST['submit'])) { $file=$_POST['uploadedfile']; $name=$_POST['name']; $yourpost=$_POST['yourpost']; $subject=$_POST['subject']; if(strlen($name)<1) { print "You did not type in a name."; //no name entered } else if(strlen($yourpost)<1) { print "You did not type in a post."; //no post entered } else if(strlen($subject)<1) { print "You did not enter a subject."; //no subject entered } else { $thedate=date("U"); //get unix timestamp $displaytime=date("F j, Y, g:i a"); //we now strip HTML injections $file=strip_tags($file); $subject=strip_tags($subject); $name=strip_tags($name); $yourpost=strip_tags($yourpost); $insertpost="INSERT INTO forumtutorial_posts(author,title,post,showtime,realtime,lastposter,image,ip) values('$name','$subject','$yourpost','$displaytime','$thedate','$name','uploadedfile','$IP')"; mysql_query($insertpost) or die("Could not insert post"); //insert post print "Your item as been posted, go back to <A href='index_forum.php'>Clasifieds</a>."; } } else { print "<form enctype='multipart/form-data' action='post.php' method='POST'>"; print "Your name:<br>"; print "<input type='text' name='name' size='20'><br>"; print "Subject:<br>"; print "<input type='text' name='subject' size='20'><br>"; print "upload a photo:<br>"; print "<input type='file' name='uploadedfile' size='20'><br>"; print "Your message:<br>"; print "<textarea name='yourpost' rows='5' cols='40'></textarea><br>"; print "<input type='submit' name='submit' value='submit'></form>"; } print "</td></tr></table>"; ?> <?php if ((($_FILES['uploadedfile']['type'] == "image/jpeg") || ($_FILES["uploadedfile"]["type"] == "image/JPG") || ($_FILES["uploadedfile"]["type"] == "image/PJPEG") || ($_FILES["uploadedfile"]["type"] == "image/jpg") || ($_FILES["uploadedfile"]["type"] == "image/pjpeg")) && ($_FILES["uploadedfile"]["size"] > 20000)) { if ($_FILES["uploadedfile"]["error"] > 0) { echo "Return Code: " . $_FILES["uploadedfile"]["error"] . "<br />"; } else { echo "Upload: " . $_FILES["uploadedfile"]["name"] . "<br />"; echo "Type: " . $_FILES["uploadedfile"]["type"] . "<br />"; echo "Size: " . ($_FILES["uploadedfile"]["size"] / 1024) . " Kb<br />"; echo "Temp file: " . $_FILES["uploadedfile"]["tmp_name"] . "<br />"; if (file_exists("uploads/" . $_FILES["uploadedfile"]["name"])) { echo $_FILES["uploadedfile"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["uploadedfile"]["tmp_name"], "uploads/" . $_FILES["uploadedfile"]["name"]); echo "Stored in: " . "uploads/" . $_FILES["uploadedfile"]["name"]; echo '<b>Your file has been uploaded successfully.</b><br /><a href="uploads/'.$_FILES['uploadedfile']['name'].'">Check it out here</a>'; $q = mysql_query("SELECT image from forumtutorial_posts"); while ($result = mysql_fetch_array($q, MYSQL_ASSOC)) { echo "<p><i>" . $result .$_FILES['image'] . ",</i></p>";//this how i thought it mat be done but it doesnt work } } } } else { echo "Invalid file"; } ?> </body> </html> when i file is uploaded its stored on my uploads folder on my server i am making a classifieds page so i wish the image to be storef in to database to be retrived later once the file is uploaded it can be viewed of the link but its not linked to the database but to the uploads folder,so can any one help me display images that are in the database thanks all
July 23, 200818 yr Author change of plan i descided to add the root of the image into the mysql using $file2=$_FILES["uploadedfile"]["name"]; then putting the image value='uploads/$file2'
July 23, 200818 yr change of plan i descided to add the root of the image into the mysql using $file2=$_FILES["uploadedfile"]["name"]; then putting the image value='uploads/$file2' does it work now, if not I will give you a hand Pat
July 23, 200818 yr Author does it work now, if not I will give you a hand Pat Thanks pat i have the image root stored into a varchar uploads/name_of_file.jpg just reading and googling for information about how to display the image now that is stord in the uploads file any ideas thanks again
July 25, 200818 yr uploads/name_of_file.jpg just reading and googling for information about how to display the image now that is stord in the uploads file any ideas thanks again Don't know if your still looking for help but the best way to do it is to store the link to the image rather than the image itslef (it looks like you're doing that now). To retrieve the image, for a list, for example something like the following should help. $query = "SELECT * FROM mytable"; $result = mysql_query($query); $numResults = mysql_num_rows($result); for($i=0;$i<$numResults; $i++){ $row = mysql_fetch_object($results); echo '<h1>'.$row->title.'</h1>'; echo '<img src="'.$row->image_name.'" alt="'.$row->image_title.'" />'; echo '<p>'.$row->description.'</p>'; } Hope this helps!
July 25, 200818 yr Author uploads/name_of_file.jpg just reading and googling for information about how to display the image now that is stord in the uploads file any ideas thanks again Don't know if your still looking for help but the best way to do it is to store the link to the image rather than the image itslef (it looks like you're doing that now). To retrieve the image, for a list, for example something like the following should help. $query = "SELECT * FROM mytable"; $result = mysql_query($query); $numResults = mysql_num_rows($result); for($i=0;$i<$numResults; $i++){ $row = mysql_fetch_object($results); echo '<h1>'.$row->title.'</h1>'; echo '<img src="'.$row->image_name.'" alt="'.$row->image_title.'" />'; echo '<p>'.$row->description.'</p>'; } Hope this helps! thankk for this i will experiment with it later thank you
July 25, 200818 yr Author thanks every one i have got it to work from displaying the image out of the blob type and also by displaying the image out out of a varchar with the root of the image name stored in the varchar from what i have been rading the latter is the best way thank you so much i can start work on my classifieds page now thanks again
Create an account or sign in to comment