nubble Posted January 29, 2008 Share Posted January 29, 2008 Hi everyone, I am a wicked newbie and am having troulbe figuring out how to insert images into a php page from a certain directory. I breed snakes, each one has an id number, like TI06W19. There's a folder on the server that holds the images for each snake, e.g. /images/TI06W19 What I want to do is write a script to insert all the images in a given folder (matching the id number I enter) that are over 10K in file size. There are thumbnails of each image in the directory, and I don't want to display those (they are all under 10K and all the large images are over 10K). I want to end up with a page where I can plug the id number in on the fly, like photos.php?critter=TI06W19. Any help would be greatly appreciated. I'm in a bit over my head Thanks! Amy Link to comment https://forums.phpfreaks.com/topic/88384-inserting-mages-into-a-page-from-a-certain-directory/ Share on other sites More sharing options...
laffin Posted January 29, 2008 Share Posted January 29, 2008 <?php isset($_GET['critter']) && $critter=$_GET['criiter']; (strpos($critter,'..')) && $critter=NULL; (isset($critter) && !is_dir($critterdir="images/$critter")) && $critter=NULL; if(empty($critter)) header("location:http://my.site.com/unknown.html"); $dh=opendir($critterdir); while($file = readdir($dh)) { if(is_file($file) && preg_match("@^.*\.(?:jpeg|jpg|gif)$@i",$file) && filesize($file)>(1024*10)) { echo "<IMG SRC=\"$critterdir/$file\"><BR>"; } } closedir($dh) ?> this shud work. header("location:http://my.site.com/unknown.html"); remember to change location, to page with unknown critters. the stuff before that checks for valid folder info. if(is_file($file) && preg_match("@^.*\.(?:jpeg|jpg|gif|png)$@i",$file) && filesize($file)>(1024*10)) { a fun line, makes shure we not looking at a folder, makes shure it is a image format than check the filesize (1024 = 1K * 10 = 10k) hope that helps. any possibility ya can pass me the url, would be neat to see what u do with the script Link to comment https://forums.phpfreaks.com/topic/88384-inserting-mages-into-a-page-from-a-certain-directory/#findComment-452392 Share on other sites More sharing options...
nubble Posted January 29, 2008 Author Share Posted January 29, 2008 Holy cow man - thank you so much! I just tried integrating the code you posted into my page, here's the URL. http://sprucenubblefarm.com/chondros/printable_chondro.php?critter=TI06W19 Something is funky because the images aren't displaying, but I'm not getting any errors. All the other php on the page is working fine. Not sure if I did something wrong. Here's the code for the page: <?php mysql_connect("mysql.blahblah.com", "blah", "blah123"); mysql_select_db("sprucen_chondros"); $sql = "SELECT `snakeID`, `locality`, `neonate_color`, `sex`, `description`, `birthyear`, `price` FROM `general` WHERE `snakeID` LIKE '$critter'"; $query = mysql_query($sql); ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Green Tree Python For Sale</title> <link href="../print.css" rel="stylesheet" type="text/css"> </head> <body> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td> <?php while($row = mysql_fetch_assoc($query)){ echo '<p class="FONT_heading">'; echo $row['birthyear']; echo " "; echo $row['locality']; echo " "; echo $row['sex']; echo '<span class="FONT_idnumber"> '; echo $row['snakeID']; echo '</span>'; echo '<hr size="1" noshade color="#5B7331">'; echo '<table width="100%"><tr><td width="70%" valign="top"><p class="FONT_text1"><span class="FONT_featured-subhead">'; echo '<b>Birthyear:</b> '; echo $row['birthyear']. '<br />'; echo '<b>Locality Type:</b> '; echo $row['locality']. '<br />'; echo '<b>Sex:</b> '; echo $row['sex']. '<br />'; echo '<b>Neonate Color:</b> '; echo $row['neonate_color'].'</span><br /><br /></p></td><td valign="top" class="FONT_price"><br><b>$'; echo $row['price'].' </b> Shipping via Delta Dash Included!<br /><span class="FONT_featured-text"> CALL<b> (207)684-3539</b> TO ORDER </span></td></tr></table><p class="FONT_text1">'; echo $row['description']. '</p>'; }?> </td> </tr> <tr> <td> </td> </tr> <tr> <td> <?php isset($_GET['critter']) && $critter=$_GET['critter']; (strpos($critter,'..')) && $critter=NULL; (isset($critter) && !is_dir($critterdir="../images/chondros/$critter")) && $critter=NULL; if(empty($critter)) header("location:http://sprucenubblefarm.com/error.html"); $dh=opendir($critterdir); while($file = readdir($dh)) { if(is_file($file) && preg_match("@^.*\.(?:jpeg|jpg|gif)$@i",$file) && filesize($file)>(1024*10)) { echo "<IMG SRC=\"$critterdir/$file\"><BR>"; } } closedir($dh) ?> </td> </tr> </table> <table width="100%" border="0" cellpadding="0" cellspacing="0"> <tr> <td align="left" valign="top"> </td> <td align="left" valign="top"> </td> <td align="left" valign="top"> </td> </tr> <tr> <td width="50%" align="left" valign="top"><table height="30" border="0" cellpadding="0" cellspacing="0" class="tab-bar"> <tr> <td align="left" class="FONT_heading">Feeding Records</td> </tr> </table> <table class="data"> <tr> <td class="data"><b>Date</b></td> <td class="data"><b>Qty</b></td> <td class="data"><b>Prey Type</b></td> <td class="data"><b>Notes</b></td> </tr> <?php $sql = "SELECT `snakeID`, `quantity`, `type`, `notes`, `date`, DATE_FORMAT(date, '%m/%d/%Y') AS `Date of Event` FROM `feedings` WHERE `snakeID` LIKE '$critter' ORDER BY date DESC"; $query = mysql_query($sql); while($row = mysql_fetch_assoc($query)){ echo '<tr><td class="data">'; echo $row['Date of Event']; echo '</td><td class="data">'; echo $row['quantity']; echo '</td><td class="data">'; echo $row['type']; echo '</td><td class="data">'; echo $row['notes']; echo '</td></tr>'; }?> </table> </td> <td width="25%" align="left" valign="top"><table height="30" border="0" cellpadding="0" cellspacing="0" class="tab-bar"> <tr> <td align="left" class="FONT_heading">Stool Records </td> </tr> </table> <table class="data"> <tr> <td class="data"><b>Date of Stool</b></td> </tr> <?php $sql = "SELECT `snakeID`, `date`, DATE_FORMAT(date, '%m/%d/%Y') AS `Date of Event` FROM `stools` WHERE `snakeID` LIKE '$critter' ORDER BY date DESC"; $query = mysql_query($sql); while($row = mysql_fetch_assoc($query)){ echo '<tr><td class="data">'; echo $row['Date of Event']; echo '</td></tr>'; }?> </table></td> <td width="25%" align="left" valign="top"> <table height="30" border="0" cellpadding="0" cellspacing="0" class="tab-bar"> <tr> <td align="left" class="FONT_heading">Care Log & Notes </td> </tr> </table> <table class="data"> <tr> <td class="data"><b>Date</b></td> <td class="data"><b>Notes</b></td> </tr> <?php $sql = "SELECT `snakeID`, `notes`, `date`, DATE_FORMAT(date, '%m/%d/%Y') AS `Date of Event` FROM `carelog` WHERE `snakeID` LIKE '$critter' ORDER BY date DESC"; $query = mysql_query($sql); while($row = mysql_fetch_assoc($query)){ echo '<tr><td class="data">'; echo $row['Date of Event']; echo '</td><td class="data">'; echo $row['notes']; echo '</td></tr>'; }?> </table></td> </tr> </table> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td> </td> <td> </td> </tr> <tr align="left" valign="top"> <td width="50%"><table height="30" border="0" cellpadding="0" cellspacing="0" class="tab-bar"> <tr> <td align="left" class="FONT_heading">Weight Records </td> </tr> </table> <table class="data"> <tr> <td class="data"><b>Date</b></td> <td class="data"><b>Weight in grams </b></td> </tr> <?php $sql = "SELECT `snakeID`, `weight`, `date`, DATE_FORMAT(date, '%m/%d/%Y') AS `Date of Event` FROM `weights` WHERE `snakeID` LIKE '$critter' ORDER BY date DESC"; $query = mysql_query($sql); while($row = mysql_fetch_assoc($query)){ echo '<tr><td class="data">'; echo $row['Date of Event']; echo '</td><td class="data">'; echo $row['weight']; echo '</td></tr>'; }?> </table></td> <td width="50%"><table height="30" border="0" cellpadding="0" cellspacing="0" class="tab-bar"> <tr> <td align="left" class="FONT_heading">Shedding Records </td> </tr> </table> <table class="data"> <tr> <td class="data"><b>Date of Shed</b></td> </tr> <?php $sql = "SELECT `snakeID`, `date`, DATE_FORMAT(date, '%m/%d/%Y') AS `Date of Event` FROM `sheds` WHERE `snakeID` LIKE '$critter' ORDER BY date DESC"; $query = mysql_query($sql); while($row = mysql_fetch_assoc($query)){ echo '<tr><td class="data">'; echo $row['Date of Event']; echo '</td></tr>'; }?> </table></td> </tr> <tr> <td> </td> <td> </td> </tr> </table> </body> </html> Link to comment https://forums.phpfreaks.com/topic/88384-inserting-mages-into-a-page-from-a-certain-directory/#findComment-452436 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.