tracy Posted December 15, 2006 Share Posted December 15, 2006 Does anyone know of a good tutorial on uploading a picture file to a folder using php and copying the name to the database in mysql? Resizing photos on upload is helpful also...If you know it works...some I have tried do not work.Not asking for someone to write code for me but info or tutorial would be nice. Or maybe a code that has worked for you that is similar that I could learn from and edit...I can upload the actual photo into the database but it slows it way down. I have heard of loading the name only and resizing the photo and sending the actual photo to a file folder on the server. The few codes I have tried were not successful. Thanks for any guidance. I appreciate it. Quote Link to comment https://forums.phpfreaks.com/topic/30792-uploading-photos-using-phpmysql/ Share on other sites More sharing options...
complex05 Posted December 15, 2006 Share Posted December 15, 2006 I wouldn't recommend putting actual images in a database, just upload the files and put the path to that file in the database. Here is a good uploading tutorialhttp://www.phpfreaks.com/tutorials/85/0.phpThen just INSERT the filename into your database :) Quote Link to comment https://forums.phpfreaks.com/topic/30792-uploading-photos-using-phpmysql/#findComment-141959 Share on other sites More sharing options...
tracy Posted December 15, 2006 Author Share Posted December 15, 2006 Exactly...name of the file in the DB, actual file in a folder...thanks. Quote Link to comment https://forums.phpfreaks.com/topic/30792-uploading-photos-using-phpmysql/#findComment-141962 Share on other sites More sharing options...
zq29 Posted December 15, 2006 Share Posted December 15, 2006 As far as uploading files, the manual has a good example that can be found here: [url=http://uk2.php.net/manual/en/features.file-upload.php]Chapter 38. Handling file uploads[/url]The file name is stored in the $_FILES['fieldname']['name'] variable, you can insert that into your database if you maintain the files original name.Resizing an image can be done with the function [url=http://uk2.php.net/manual/en/function.imagecopyresampled.php]imagecopyresampled()[/url] - There is also a good example of its use on that manual page. (Assuming you have GDLib installed on the server / enabled in your php.ini) Quote Link to comment https://forums.phpfreaks.com/topic/30792-uploading-photos-using-phpmysql/#findComment-141964 Share on other sites More sharing options...
complex05 Posted December 15, 2006 Share Posted December 15, 2006 If you really do what to put the images directly into the database, here is a good tutorial on how to do it.http://www.phpfreaks.com/tutorials/85/0.phpHope that helps! Quote Link to comment https://forums.phpfreaks.com/topic/30792-uploading-photos-using-phpmysql/#findComment-141967 Share on other sites More sharing options...
tracy Posted December 15, 2006 Author Share Posted December 15, 2006 I don't want the images in the database...I want the images in a file folder and the name of the image in the database, for speed.I can upload images to the database, no problem. My current code does that. It just slows everything to a crawl.I now want info on how to upload the picture file to a folder (resizing it to 200x200pixels on the way up) and reference said file in the database...Any info on exactly how to do that is appreciated...or tutorial that actually works...or sample code that works...I could alter.Thanks again. Quote Link to comment https://forums.phpfreaks.com/topic/30792-uploading-photos-using-phpmysql/#findComment-141968 Share on other sites More sharing options...
zq29 Posted December 15, 2006 Share Posted December 15, 2006 [quote author=tracy link=topic=118784.msg485671#msg485671 date=1166214381]I don't want the images in the database...I want the images in a file folder and the name of the image in the database, for speed.I can upload images to the database, no problem. My current code does that. It just slows everything to a crawl.I now want info on how to upload the picture file to a folder (resizing it to 200x200pixels on the way up) and reference said file in the database...Any info on exactly how to do that is appreciated...or tutorial that actually works...or sample code that works...I could alter.Thanks again.[/quote]Did you check out the resources I posted in my reply? They should have the answers you require, with examples. Quote Link to comment https://forums.phpfreaks.com/topic/30792-uploading-photos-using-phpmysql/#findComment-141971 Share on other sites More sharing options...
tracy Posted December 15, 2006 Author Share Posted December 15, 2006 Thanks...reviewing now...I appreciate it. Quote Link to comment https://forums.phpfreaks.com/topic/30792-uploading-photos-using-phpmysql/#findComment-141974 Share on other sites More sharing options...
tracy Posted December 18, 2006 Author Share Posted December 18, 2006 I did quite a bit of reading here. I did not find the info I needed in a format I could use, as I am new to php.Here are the issues I'm considering:1. I need to use an upload form which I will attach code for at the bottom of this message. It contains ability to load six photos.2. I need every photo (all jpegs) to be converted to 200x200 pixels or smaller upon upload.3. I need them to be stored in a file folder on the server, named in such a way that they can be identified by mysql.4. I need the corresponding name stored in the actual mysql database table.5. I can call the storage file folder virtually anything, like ______imagefile with the _____ being the table name...I will have several tables in each database so I would likely create a file for holding images for each table in the database.The info you supplied was good, it just did not seem to address all three procedures combined...resize on upload, store resized image in file and send corresponding name of thumbnail to database table...AND...can six be done at once with the same form?AND...what happens to the actual photo after it is thumbnailed? I don't really care if it never makes it to the file, as long as the thumbnail does...Thanks. I appreciate your help so far.Here's the table upload form so you might have an idea of what I am uploading. It is an auto inventory display.<html><title>Add Vehicle Form</title><body><form action="insert.php" method="post"><table><tr><td>Stock Number:</td><td><input type="text" name="stock" /></td></tr><td>Year:</td><td><input type="text" name="year" /></td></tr><td>Make:</td><td><input type="text" name="make" /></td></tr><td>Model:</td><td><input type="text" name="model" /></td></tr><td>Price:</td><td><input type="text" name="price" /></td></tr><td>Miles:</td><td><input type="text" name="miles" /></td></tr><td>Photo1:</td><td><input type="file" name="photo1" /></td></tr><td>Photo2:</td><td><input type="file" name="photo2" /></td></tr><td>Photo3:</td><td><input type="file" name="photo3" /></td></tr><td>Photo4:</td><td><input type="file" name="photo4" /></td></tr><td>Photo5:</td><td><input type="file" name="photo5" /></td></tr><td>Photo61:</td><td><input type="file" name="photo6" /></td></tr><input type="submit" /></form></body></html>[quote author=SemiApocalyptic link=topic=118784.msg485667#msg485667 date=1166214148]As far as uploading files, the manual has a good example that can be found here: [url=http://uk2.php.net/manual/en/features.file-upload.php]Chapter 38. Handling file uploads[/url]The file name is stored in the $_FILES['fieldname']['name'] variable, you can insert that into your database if you maintain the files original name.Resizing an image can be done with the function [url=http://uk2.php.net/manual/en/function.imagecopyresampled.php]imagecopyresampled()[/url] - There is also a good example of its use on that manual page. (Assuming you have GDLib installed on the server / enabled in your php.ini)[/quote] Quote Link to comment https://forums.phpfreaks.com/topic/30792-uploading-photos-using-phpmysql/#findComment-143575 Share on other sites More sharing options...
craygo Posted December 18, 2006 Share Posted December 18, 2006 Do you need both, an insert form and an update form?? Is this for the other form we helped you with before??Ray Quote Link to comment https://forums.phpfreaks.com/topic/30792-uploading-photos-using-phpmysql/#findComment-143621 Share on other sites More sharing options...
tracy Posted December 18, 2006 Author Share Posted December 18, 2006 This is a similar version of that form. I can write both the html form and the php insert form now, no problem. The issue is with the insert form. I have used it successfully to upload photos to the database. The problem with this method is speed...displaying the table is slow with all these large photo files in the table (mysql).As far as what I am trying to do now, I can't successfully insert the portion of code that causes the photo to be thumbnailed and sent to a file while sending the image thumbnail name to the database. I tried an online tutorial but it was a disaster. Not even worth posting it was so bad. I'd like to see an actual working version of the thumbnail part so I can see how it works and how it is structured. Then with the tutorial and my research in the php manual I could probably successfully do my own...In your experience, if I thumbnail the images to 200x200 or so, would I even need to send the thumbnail to the file? Or would my data table pull up rather quickly with 200 or so thumbnails in the actual database? I think it would be way too slow... [quote author=craygo link=topic=118784.msg487341#msg487341 date=1166454669]Do you need both, an insert form and an update form?? Is this for the other form we helped you with before??Ray[/quote] Quote Link to comment https://forums.phpfreaks.com/topic/30792-uploading-photos-using-phpmysql/#findComment-143629 Share on other sites More sharing options...
craygo Posted December 18, 2006 Share Posted December 18, 2006 Let me ask you this. Do you want to keep both the larger file and have a thumbnail? That way the page should load fast but also will have a full size image for viewing if desired.Ray Quote Link to comment https://forums.phpfreaks.com/topic/30792-uploading-photos-using-phpmysql/#findComment-143666 Share on other sites More sharing options...
tracy Posted December 18, 2006 Author Share Posted December 18, 2006 That part doesn't matter that much to me...here's why:1. If I thumbnail the images to 125x125 for example, really small, I will need the original photo...2. If I thumbnail to 250x250 or so, medium size, then the original can be deleted, lost, whatever...Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/30792-uploading-photos-using-phpmysql/#findComment-143668 Share on other sites More sharing options...
craygo Posted December 18, 2006 Share Posted December 18, 2006 OK one last thing. If you want to be able to store 6 images, do you want to store each image in it's own field or all images in one field??Ray Quote Link to comment https://forums.phpfreaks.com/topic/30792-uploading-photos-using-phpmysql/#findComment-143672 Share on other sites More sharing options...
tracy Posted December 18, 2006 Author Share Posted December 18, 2006 Like in the html form above, each photo will have its own cell in the mysql table...and there can be actually no photos, so I'd set those fields to allow nothing there or the thumbnailed file names... Quote Link to comment https://forums.phpfreaks.com/topic/30792-uploading-photos-using-phpmysql/#findComment-143675 Share on other sites More sharing options...
craygo Posted December 18, 2006 Share Posted December 18, 2006 OK try this out. Make sure you change the paths at the top and put in your mysql connection.[code]<?php$absolute_path = "/path/to/your/full/size/image/folder"; //Absolute path to where files are uploaded$thumb_path = "/path/to/thumbnail/folder"; //Absolute path to where thumbs are to be stored if you want this$size_limit = "yes"; //do you want a size limit yes or no.$limit_size = "600000"; //How big do you want size limit to be in bytes$limit_ext = "yes"; //do you want to limit the extensions of files uploaded$ext_count = "1"; //total number of extensions in array below$extensions = array(".jpg"); //List extensions you want files uploaded to befunction resampimagejpg($forcedwidth, $forcedheight, $sourcefile, $destfile, $imgcomp) { $g_imgcomp=100-$imgcomp; $g_srcfile=$sourcefile; $g_dstfile=$destfile; $g_fw=$forcedwidth; $g_fh=$forcedheight; if(file_exists($g_srcfile)) { $g_is=getimagesize($g_srcfile); if(($g_is[0]-$g_fw)>=($g_is[1]-$g_fh)) { $g_iw=$g_fw; $g_ih=($g_fw/$g_is[0])*$g_is[1]; } else { $g_ih=$g_fh; $g_iw=($g_ih/$g_is[1])*$g_is[0]; } $img_src=imagecreatefromjpeg($g_srcfile); $img_dst=imagecreatetruecolor($g_iw,$g_ih); imagecopyresampled($img_dst, $img_src, 0, 0, 0, 0, $g_iw, $g_ih, $g_is[0], $g_is[1]); imagejpeg($img_dst, $g_dstfile, $g_imgcomp); imagedestroy($img_dst); return true; } else return false; }if(!isset($_POST['submit'])){ if (($extensions == "") or ($extensions == " ") or ($ext_count == "0") or ($ext_count == "") or ($limit_ext != "yes") or ($limit_ext == "")) { $extens = "any extension"; } else { $ext_count2 = $ext_count+1; for($counter=0; $counter<$ext_count; $counter++) { $extens = " $extensions[$counter]"; } } if (($limit_size == "") or ($size_limit != "yes")) { $limit_size = "any size"; } else { $limit_size .= " bytes"; $mb_size = ($limit_size/1000000); } $pichead = "<li><font size=\"2\" color=660000>File extension must be $extens<b>"; $pichead .="</b></font> <li><font size=\"2\" color=660000>Maximum file size is $limit_size ($mb_size MB)</font></li> <li><font size=\"2\" color=660000>No spaces in the filename</font></li>";?><html><head><title>HTML Form for uploading image to server</title></head><body><form action="" method="post" enctype="multipart/form-data"><html><title>Add Vehicle Form</title><body><form action="<?=$_SERVER['PHP_SELF']?>" method="post"><table width=400 align=center><tr><td>Stock Number:</td><td><input type="text" name="stock" /></td></tr><td>Year:</td><td><input type="text" name="year" /></td></tr><td>Make:</td><td><input type="text" name="make" /></td></tr><td>Model:</td><td><input type="text" name="model" /></td></tr><td>Price:</td><td><input type="text" name="price" /></td></tr><td>Miles:</td><td><input type="text" name="miles" /></td></tr><tr><td colspan=2 align=center><?=$pichead?><p>Pictures:<br />1 <input type="file" name="pictures[]" /><br />2 <input type="file" name="pictures[]" /><br />3 <input type="file" name="pictures[]" /><br />4 <input type="file" name="pictures[]" /><br />5 <input type="file" name="pictures[]" /><br />6 <input type="file" name="pictures[]" /><br /><input type="submit" name=submit value="Send" /></p></form></body></html><?php} else {$i=0;$photoarray = array(); foreach ($_FILES["pictures"]["error"] as $key => $error) { $file_name = $_FILES["pictures"]['name'][$i]; // can call this anything you like this will take the original name $file = $_FILES["pictures"]['tmp_name'][$i]; $photoarray[$i+1]= $file_name; $endresult = "<font size=\"4\" color=990000>$file_name uploaded successfully</font>"; if ($file_name == "") { $pic = $i+1; $endresult = "<font size=\"4\" color=990000>Pic#$pic Not selected</font>"; }else{ if(file_exists("$absolute_path/$file_name")) { $endresult = "<font size=\"4\" color=990000>File Already Existed</font>"; } else { if (($size_limit == "yes") && ($limit_size < $file_size)) { $endresult = "<font size=\"4\" color=990000>File was to big</font>"; } else { $ext = strrchr($file_name,'.'); if (($limit_ext == "yes") && (!in_array($ext,$extensions))) { $endresult = "<font size=\"4\" color=990000>File is wrong type</font>"; }else{ // Save full size image with max width/height resampimagejpg(1000,1000,$file,"$absolute_path/$file_name",0); // Save thumb image with max width/height of 200 resampimagejpg(200,200,$file,"$thumb_path/$file_name",0); } } } } $i++; echo $endresult."<br>"; }/********* Connection to mysql below **********//*********** End connection string ************/$sql = "INSERT INTO inventory SET stock = '".$_POST['stock']."', year = '".$_POST['year']."', make = '".$_POST['make']."', model = '".$_POST['model']."', miles = '".$_POST['miles']."', price = '".$_POST['price']."', photo1 = '".$photoarray[1]."', photo2 = '".$photoarray[2]."', photo3 = '".$photoarray[3]."', photo4 = '".$photoarray[4]."', photo5 = '".$photoarray[5]."', photo6 = '".$photoarray[6]."'";$res = mysql_query($sql);if(!$res){echo "Could not insert Row<br>Error: ".mysql_error()."<br>SQL: ".$sql;} else {echo "Row inserted";}}?></body></html>[/code]Ray Quote Link to comment https://forums.phpfreaks.com/topic/30792-uploading-photos-using-phpmysql/#findComment-143716 Share on other sites More sharing options...
tracy Posted December 18, 2006 Author Share Posted December 18, 2006 I'll check it out...thanks...I appreciate it. Quote Link to comment https://forums.phpfreaks.com/topic/30792-uploading-photos-using-phpmysql/#findComment-143719 Share on other sites More sharing options...
tracy Posted December 18, 2006 Author Share Posted December 18, 2006 I keep getting an error on line 34...I changed permissions to 777 on the images folder and the thumbnails folder, which is in the images folder...did not work at all.Changed them back...Now it gives error on line 34...can the thumbnail folder be inside the images folder?[quote author=craygo link=topic=118784.msg487436#msg487436 date=1166461556]OK try this out. Make sure you change the paths at the top and put in your mysql connection.[code]<?php$absolute_path = "/path/to/your/full/size/image/folder"; //Absolute path to where files are uploaded$thumb_path = "/path/to/thumbnail/folder"; //Absolute path to where thumbs are to be stored if you want this$size_limit = "yes"; //do you want a size limit yes or no.$limit_size = "600000"; //How big do you want size limit to be in bytes$limit_ext = "yes"; //do you want to limit the extensions of files uploaded$ext_count = "1"; //total number of extensions in array below$extensions = array(".jpg"); //List extensions you want files uploaded to befunction resampimagejpg($forcedwidth, $forcedheight, $sourcefile, $destfile, $imgcomp) { $g_imgcomp=100-$imgcomp; $g_srcfile=$sourcefile; $g_dstfile=$destfile; $g_fw=$forcedwidth; $g_fh=$forcedheight; if(file_exists($g_srcfile)) { $g_is=getimagesize($g_srcfile); if(($g_is[0]-$g_fw)>=($g_is[1]-$g_fh)) { $g_iw=$g_fw; $g_ih=($g_fw/$g_is[0])*$g_is[1]; } else { $g_ih=$g_fh; $g_iw=($g_ih/$g_is[1])*$g_is[0]; } $img_src=imagecreatefromjpeg($g_srcfile); $img_dst=imagecreatetruecolor($g_iw,$g_ih); imagecopyresampled($img_dst, $img_src, 0, 0, 0, 0, $g_iw, $g_ih, $g_is[0], $g_is[1]); imagejpeg($img_dst, $g_dstfile, $g_imgcomp); imagedestroy($img_dst); return true; } else return false; }if(!isset($_POST['submit'])){ if (($extensions == "") or ($extensions == " ") or ($ext_count == "0") or ($ext_count == "") or ($limit_ext != "yes") or ($limit_ext == "")) { $extens = "any extension"; } else { $ext_count2 = $ext_count+1; for($counter=0; $counter<$ext_count; $counter++) { $extens = " $extensions[$counter]"; } } if (($limit_size == "") or ($size_limit != "yes")) { $limit_size = "any size"; } else { $limit_size .= " bytes"; $mb_size = ($limit_size/1000000); } $pichead = "<li><font size=\"2\" color=660000>File extension must be $extens<b>"; $pichead .="</b></font> <li><font size=\"2\" color=660000>Maximum file size is $limit_size ($mb_size MB)</font></li> <li><font size=\"2\" color=660000>No spaces in the filename</font></li>";?><html><head><title>HTML Form for uploading image to server</title></head><body><form action="" method="post" enctype="multipart/form-data"><html><title>Add Vehicle Form</title><body><form action="<?=$_SERVER['PHP_SELF']?>" method="post"><table width=400 align=center><tr><td>Stock Number:</td><td><input type="text" name="stock" /></td></tr><td>Year:</td><td><input type="text" name="year" /></td></tr><td>Make:</td><td><input type="text" name="make" /></td></tr><td>Model:</td><td><input type="text" name="model" /></td></tr><td>Price:</td><td><input type="text" name="price" /></td></tr><td>Miles:</td><td><input type="text" name="miles" /></td></tr><tr><td colspan=2 align=center><?=$pichead?><p>Pictures:<br />1 <input type="file" name="pictures[]" /><br />2 <input type="file" name="pictures[]" /><br />3 <input type="file" name="pictures[]" /><br />4 <input type="file" name="pictures[]" /><br />5 <input type="file" name="pictures[]" /><br />6 <input type="file" name="pictures[]" /><br /><input type="submit" name=submit value="Send" /></p></form></body></html><?php} else {$i=0;$photoarray = array(); foreach ($_FILES["pictures"]["error"] as $key => $error) { $file_name = $_FILES["pictures"]['name'][$i]; // can call this anything you like this will take the original name $file = $_FILES["pictures"]['tmp_name'][$i]; $photoarray[$i+1]= $file_name; $endresult = "<font size=\"4\" color=990000>$file_name uploaded successfully</font>"; if ($file_name == "") { $pic = $i+1; $endresult = "<font size=\"4\" color=990000>Pic#$pic Not selected</font>"; }else{ if(file_exists("$absolute_path/$file_name")) { $endresult = "<font size=\"4\" color=990000>File Already Existed</font>"; } else { if (($size_limit == "yes") && ($limit_size < $file_size)) { $endresult = "<font size=\"4\" color=990000>File was to big</font>"; } else { $ext = strrchr($file_name,'.'); if (($limit_ext == "yes") && (!in_array($ext,$extensions))) { $endresult = "<font size=\"4\" color=990000>File is wrong type</font>"; }else{ // Save full size image with max width/height resampimagejpg(1000,1000,$file,"$absolute_path/$file_name",0); // Save thumb image with max width/height of 200 resampimagejpg(200,200,$file,"$thumb_path/$file_name",0); } } } } $i++; echo $endresult."<br>"; }/********* Connection to mysql below **********//*********** End connection string ************/$sql = "INSERT INTO inventory SET stock = '".$_POST['stock']."', year = '".$_POST['year']."', make = '".$_POST['make']."', model = '".$_POST['model']."', miles = '".$_POST['miles']."', price = '".$_POST['price']."', photo1 = '".$photoarray[1]."', photo2 = '".$photoarray[2]."', photo3 = '".$photoarray[3]."', photo4 = '".$photoarray[4]."', photo5 = '".$photoarray[5]."', photo6 = '".$photoarray[6]."'";$res = mysql_query($sql);if(!$res){echo "Could not insert Row<br>Error: ".mysql_error()."<br>SQL: ".$sql;} else {echo "Row inserted";}}?></body></html>[/code]Ray[/quote] Quote Link to comment https://forums.phpfreaks.com/topic/30792-uploading-photos-using-phpmysql/#findComment-143737 Share on other sites More sharing options...
tracy Posted December 18, 2006 Author Share Posted December 18, 2006 my database is actually updating fine, which is good since I have had difficulty before to make that happen using a self form...the names of the images in the corresponding cells are the original names...just like the loaded name. But they won't pull out of the file and show...I think this file you sent works, I just need to adjust my display php...I'll work on that on my own for now before I trouble you...thanks again... Quote Link to comment https://forums.phpfreaks.com/topic/30792-uploading-photos-using-phpmysql/#findComment-143745 Share on other sites More sharing options...
tracy Posted December 18, 2006 Author Share Posted December 18, 2006 Why wouldn't this display the table with the photo from photo1 cell?It worked before? It's actually still working for all other cells just not the photo cells...red x only...I looked at the code and it seems it should work. It should access that database cell, which should access the photo...<?php include ("link.php"); $query= mysql_query("SELECT * FROM inventory") or die("ERROR:" . mysql_error()); $num = mysql_num_rows($query); if ($num == '0') { echo "Nothing Exist."; die(); } else { ?> <table border="0" cellspacing="2" cellpadding="2"> <tr> <td><font face=Arial>Stock#</font> </td> <td><font face=Arial>Year</font> </td> <td><font face=Arial>Make</font> </td> <td><font face=Arial>Model</font> </td> <td><font face=Arial>Price</font> </td> <td><font face=Arial>Miles</font> </td> <td><font face=Arial>Photo1</font> </td> </tr> <? while ($info = mysql_fetch_array($query)) { $stock = $info['stock']; $year = $info['year']; $make = $info['make']; $model = $info['model']; $price = $info['price']; $miles = $info['miles']; $photo1 = $info['photo1']; echo ("<tr><td> <font face=Arial>".$stock."</font></td><td> <font face=Arial>".$year."</font></td><td> <font face=Arial>".$make."</font></td><td> <font face=Arial>".$model."</font></td><td> <font face=Arial>".$price."</font></td><td> <font face=Arial>".$miles."</font></td><td> <font face=Arial><img src=".$photo1."></font></td></tr>"); } ?> </table> <? } ?> Quote Link to comment https://forums.phpfreaks.com/topic/30792-uploading-photos-using-phpmysql/#findComment-143751 Share on other sites More sharing options...
craygo Posted December 18, 2006 Share Posted December 18, 2006 The database only contains the file name, not the path[code]<font face=Arial><img src="/path/to/file/$photo1">[/code]Ray Quote Link to comment https://forums.phpfreaks.com/topic/30792-uploading-photos-using-phpmysql/#findComment-143775 Share on other sites More sharing options...
tracy Posted December 18, 2006 Author Share Posted December 18, 2006 But we can't put the path in the database, right? We put the path in the display page? Then how does that work?Here is my display page, that shows the red x where the photo should be...my instinct is to put the path and file name in the proper section of this code...would that work?<?php include ("link.php"); $query= mysql_query("SELECT * FROM inventory") or die("ERROR:" . mysql_error()); $num = mysql_num_rows($query); if ($num == '0') { echo "Nothing Exist."; die(); } else { ?> <table border="0" cellspacing="2" cellpadding="2"> <tr> <td><font face=Arial>Stock#</font> </td> <td><font face=Arial>Year</font> </td> <td><font face=Arial>Make</font> </td> <td><font face=Arial>Model</font> </td> <td><font face=Arial>Price</font> </td> <td><font face=Arial>Miles</font> </td> <td><font face=Arial>Photo1</font> </td> </tr> <? while ($info = mysql_fetch_array($query)) { $stock = $info['stock']; $year = $info['year']; $make = $info['make']; $model = $info['model']; $price = $info['price']; $miles = $info['miles']; $photo1 = $info['photo1']; echo ("<tr><td> <font face=Arial>".$stock."</font></td><td> <font face=Arial>".$year."</font></td><td> <font face=Arial>".$make."</font></td><td> <font face=Arial>".$model."</font></td><td> <font face=Arial>".$price."</font></td><td> <font face=Arial>".$miles."</font></td><td> <font face=Arial><img src=".$photo1."></font></td></tr>"); } ?> </table> <? } ?> Quote Link to comment https://forums.phpfreaks.com/topic/30792-uploading-photos-using-phpmysql/#findComment-143779 Share on other sites More sharing options...
craygo Posted December 18, 2006 Share Posted December 18, 2006 You can do it either way. Usually you would set the path at the top of the document the just call the photo name from the database. But you can also store the full path in the table if you like.Let me know which one you want to doRay Quote Link to comment https://forums.phpfreaks.com/topic/30792-uploading-photos-using-phpmysql/#findComment-143782 Share on other sites More sharing options...
tracy Posted December 18, 2006 Author Share Posted December 18, 2006 I'd like it at the top if that's ok...that way it's easier to change the pages for different databases and probably better code...thanks. Quote Link to comment https://forums.phpfreaks.com/topic/30792-uploading-photos-using-phpmysql/#findComment-143783 Share on other sites More sharing options...
craygo Posted December 18, 2006 Share Posted December 18, 2006 [code]<?phpinclude('link.php');// Link to thumbnail images in reference to where this page is$thumb_path = "thumbs"; // this will be in a thumbs folder in the same directory as this file// Link to full size images in reference to where this page is$full_path = "."; // this would mean the full size images are in this same folder$query= mysql_query("SELECT * FROM inventory") or die("ERROR:" . mysql_error());$num = mysql_num_rows($query);if ($num == '0') {echo "Nothing Exist.";die();}else {?><table border="0" cellspacing="2" cellpadding="2"><tr><td><font face=Arial>Stock#</font></td><td><font face=Arial>Year</font></td><td><font face=Arial>Make</font></td><td><font face=Arial>Model</font></td><td><font face=Arial>Price</font></td><td><font face=Arial>Miles</font></td><td><font face=Arial>Photo1</font></td></tr><?phpwhile ($info = mysql_fetch_array($query)) {$stock = $info['stock'];$year = $info['year'];$make = $info['make'];$model = $info['model'];$price = $info['price'];$miles = $info['miles'];$photo1 = $info['photo1'];echo ("<tr><td> <font face=Arial>".$stock."</font></td><td> <font face=Arial>".$year."</font></td><td> <font face=Arial>".$make."</font></td><td> <font face=Arial>".$model."</font></td><td> <font face=Arial>".$price."</font></td><td> <font face=Arial>".$miles."</font></td><td> <font face=Arial><a href=\"".$full_path."/".$photo1."\"><img src=\"".$thumb_path."/".$photo1."\"></a></font></td></tr>");}?></table><?php}?>[/code]Ray Quote Link to comment https://forums.phpfreaks.com/topic/30792-uploading-photos-using-phpmysql/#findComment-143790 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.