PHP - Display Images From Different Sub-folders Located In One Folder
Similar TutorialsI have this script from http://lampload.com/...,view.download/ (I am not using a database) I can upload images fine, I can view files, but I want to delete them. When I press the delete button, nothing happens
http://www.jayg.co.u...oad_gallery.php
<form>
<?php $dir = dirname(__FILENAME__)."/images/gallery" ; $files1 = scandir($dir); foreach($files1 as $file){ if(strlen($file) >=3){ $foil = strstr($file, 'jpg'); // As of PHP 5.3.0 $foil = $file; $pos = strpos($file, 'css'); if ($foil==true){ echo '<input type="checkbox" name="filenames[]" value="'.$foil.'" />'; echo "<img width='130' height='38' src='images/gallery/$file' /><br/>"; // for live host //echo "<img width='130' height='38' src='/ABOOK/SORTING/gallery-dynamic/images/gallery/ $file' /><br/>"; } } }?> <input type="submit" name="mysubmit2" value="Delete"> </form>
any ideas please?
thanks
Im using this code to call all the images in a folder: Code: [Select] $handle = opendir(dirname(realpath(__FILE__)).'/images/'); while($file = readdir($handle)){ if($file !== '.' && $file !== '..'){ echo '<img src="admin/img/uploads/'.$file.'" border="0" />'; } } My html says the images are present but they aren't visable on screen: Code: [Select] <div id="contentbody"> <img src="admin/img/uploads/send-button-sprite copy.png" border="0" /> <img src="admin/img/uploads/test" border="0" /> <img src="admin/img/uploads/counter.jpg" border="0" /> <img src="admin/img/uploads/send-button-sprite.png" border="0" /> </div> Any help is much appreciated! Hello once again, i got this code that takes all images from a folder and displays them close to each other. Heres the code: <?php $dir = 'uploads/thumbs/watermarkedthumbs/'; $file_display = array ('jpg', 'jpeg', 'png', 'gif'); if (file_exists($dir) == false) { echo 'tt'; } else { $dir_contents = scandir($dir); foreach ($dir_contents as $file) { $file_type = strtolower(end(explode('.', $file))); if ($file !== '.' && $file !== '..' && in_array($file_type, $file_display) == true) { echo '<img src="', $dir, '/', $file, '" alt="', $file, '" />'; } } } ?> How do i add margins in between them? i wanna make it smth like 'margin-left:10px, margin-top-10px'. Also, how do i add an 'overflow'? i mean, my images currently are displayed in a div, and i wanna make it so that if the folder has lets say 9 images, it would only display 6 of them, and the rest would be displayed in the same div after i click a button or smth (like '1' for the first div and '2' would appear if theres an overflow, and when i click '2' the rest of the images would appear). To make these adjustments do i need to make a different php file or do i change something in this code? thanks in advance. I'm working on creating a Realtors website. Currently mysql DB has 4 tables. 3 of them are needed in this script to show up as 1 item. Table called Listings has 2 fields that call on 2 other tables. one is MLS which calls on the Images Table the other agent calls on the Agents table. I'm trying to see why I can't While loop all 3 tables together? How can I connect all 3? <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; } $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } //mysql_select_db($database_CarneyRealty, $CarneyRealty); //$query_Update1 = "SELECT * FROM listings"; //$Update1 = mysql_query($query_Update1, $CarneyRealty) or die(mysql_error()); //$rrows = mysql_fetch_assoc($Update1); //$totalRows_Update1 = mysql_num_rows($Update1); include 'dbc.php'; page_protect(); $err = array(); $msg = array(); $page_limit =4; //CHANGE FOR THE NUMBER OF LISTINGS PER PAGE! $page_num_limit =10; $ret = $_SERVER['HTTP_REFERER']; $host = $_SERVER['HTTP_HOST']; $host_upper = strtoupper($host); $login_path = @ereg_replace('admin','',dirname($_SERVER['PHP_SELF'])); $path = rtrim($login_path, '/\\'); // filter GET values foreach($_GET as $key => $value) { $get[$key] = filter($value); } foreach($_POST as $key => $value) { $post[$key] = filter($value); } $rs_all = mysql_query("select count(*) as total_all from listings") or die(mysql_error()); $rs_active = mysql_query("select count(*) as total_active from listings where status='ACTIVE'") or die(mysql_error()); $rs_total_contingent = mysql_query("select count(*) as tot2 from listings where status='CONTINGENT'"); $rs_total_pending = mysql_query("select count(*) as tot from listings where status='PENDING'"); $rs_total_sold = mysql_query("select count(*) as tot1 from listings where status='SOLD'"); $rs_resall = mysql_query("select count(*) as res from listings where class='Resident'") or die(mysql_error()); $rs_comall = mysql_query("select count(*) as com from listings where class='Commerical'"); $rs_farmall = mysql_query("select count(*) as farm from listings where class='Farmland'"); $rs_otherall = mysql_query("select count(*) as other from listings where class='Other'"); list($all) = mysql_fetch_row($rs_all); list($active) = mysql_fetch_row($rs_active); list($total_contingent) = mysql_fetch_row($rs_total_contingent); list($total_pending) = mysql_fetch_row($rs_total_pending); list($total_sold) = mysql_fetch_row($rs_total_sold); list($resall) = mysql_fetch_row($rs_resall); list($comall) = mysql_fetch_row($rs_comall); list($farmall) = mysql_fetch_row($rs_farmall); list($otherall) = mysql_fetch_row($rs_otherall); /////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////// $sqlagents = mysql_query("select * from agents where id='$_SESSION'"); //$agentname= mysql_query($sqlagents) or die(mysql_error()); $sqllistings = mysql_query("select * from listings where id='$_SESSION'"); $sqlimages = mysql_query("select * from images where id='$_SESSION'"); //////////////////////////////////////////////////////////////////////////////////////////////////////// ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>Search CarneyRealty Listings</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <link rel="stylesheet" href="../css/mm_brochure.css" type="text/css"> <style type="text/css"> <!-- body { background-image: url(http://www.carneyrealty.com/newsite/images/IMG_0161a.jpg); } .style1 { font-size: 16px } .style2 { font-family: Geneva, Arial, Helvetica, sans-serif } .style10 { font-size: 13px; font-weight: bold; color: #FF0000; } .style7 { color: #FF0000; font-weight: bold; } .style8 { color: #0000FF; font-weight: bold; } --> </style> </head> <body bgcolor="#bcbc85" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"> <div align="center"> <table width="81%" border="0" cellspacing="0" cellpadding="0"> <tr bgcolor="#999966"> <td width="25" nowrap="nowrap"><center> <img src="../images/mm_spacer.gif" alt="" width="15" height="1" border="0" /></td> <td height="60" colspan="3" class="logo" nowrap="nowrap"><div align="center"><img src="images/Carney_Logo1_000.jpg" width="630" height="158" /><br /> </div></td> <td width="4"></td> </tr> <tr bgcolor="#797947"> <td width="25" nowrap="nowrap"></td> <td colspan="3" valign="top"><div align="center"> <table width="460" border="0" cellpadding="0" cellspacing="0" id="navigation"> <tr> <td width="59" align="center" nowrap="nowrap"><div align="center"><a href="../index.htm" class="style1"><strong>HOME</a></div></td> <td width="127" align="center" nowrap="nowrap"><div align="center"><strong><a href="../SearchCarneyRealtyListings.php" class="style5">LISTINGSEARCH</a></strong></div></td> <td width="94" align="center" nowrap="nowrap"><div align="center"><strong><a href="../Aboutus.html" class="style5">ABOUT US</a></strong></div></td> <td width="10" align="center" nowrap="nowrap"><div align="center"></div></td> <td width="95" align="center" nowrap="nowrap"><div align="center"><strong><a href="../Community.htm" class="style5">COMMUNITY </a></strong></div></td> <td width="81" align="center" nowrap="nowrap"><div align="center"><strong><a href="../Login.php" class="style5">LOGIN</a></strong></div></td> </tr> </table> <table width="307" border="0" cellpadding="0" cellspacing="0" id="navigation"> <tr> <td width="84" align="center" nowrap="nowrap"><div align="center"><a href="http://www.carneyrealty.com/newsite/listingsearch.php?doSearch=MLS+Search&q=Resident" class="style1">Residential</a></div></td> <td width="103" align="center" nowrap="nowrap"><div align="center"><strong><a href="http://www.carneyrealty.com/newsite/listingsearch.php?doSearch=MLS+Search&q=Commerical" class="style5">Commercial</a></strong></div></td> <td width="102" align="center" nowrap="nowrap"><div align="center"><strong><a href="http://www.carneyrealty.com/newsite/listingsearch.php?doSearch=MLS+Search&q=Farmland" class="style5">Farms & Land</a></strong></div></td> <td width="18" align="center" nowrap="nowrap"><div align="center"></div></td> </tr> </table> <table width="573" border="0" cellpadding="0" cellspacing="0" id="navigation"> <tr> <td width="72" align="center" nowrap="nowrap"><div align="center"><a href="residental0-60.php" class="style1">$0-$60K</a></div></td> <td width="80" align="center" nowrap="nowrap"><div align="center"><strong><a href="residental61-85.php" class="style5">$61K-$85K</a></strong></div></td> <td width="87" align="center" nowrap="nowrap"><div align="center"><strong><a href="residental86-115.php" class="style5">$86K-$115K</a></strong></div></td> <td width="1" align="center" nowrap="nowrap"><div align="center"></div></td> <td width="103" align="center" nowrap="nowrap"><div align="center"><strong><a href="residental116-160.php" class="style5">$116K-$160K</a></strong></div></td> <td width="93" align="center" nowrap="nowrap"><div align="center"><strong><a href="residental161-230.php" class="style5">$161K-230K</a></strong></div></td> <td width="126" align="center" nowrap="nowrap"><div align="center"><strong><a href="residential231up.php" class="style5">$231K-And Up</a></strong></div></td> <td width="11" align="center" nowrap="nowrap"> </td> </tr> </table> </div></td> </tr> <td width="25" valign="top"><?php /*********************** MY MLS MENU **************************** This code shows MLS account menu only to logged in users. Copy this code till END and place it in a new html or php where you want to show myaccount options. This is only visible to logged in users *******************************************************************/ ?> <?php if(!empty($msg)) { echo $msg[0]; } ?> <? //$row_settings1=mysql_fetch_array($sqllistings1);?> <?php while ($row_settings1 = mysql_fetch_array($sqllistings)){ $row_settings2=mysql_fetch_array($sqlimages); $row_settings3=mysql_fetch_array($sqlagents); ?> <?php } ?> </table> <table width="81%" border="0" align="center" cellpadding="10" cellspacing="0" style="background-color: #FF9933;padding: 2px 5px;border: 1px solid #F90;" > <tr> <td height="44" align="center"><form name="form1" method="get" action="listingsearch.php"> <p> <input name="doSearch" type="submit" id="doSearch2" value="MLS Search" /> <input name="q" type="text" id="q" size="40"> <strong> S CARNEY& ASSOCIATES INC 800-757-5783</strong> <br> </p> </form></td> </tr> </table> </td> </tr> </table> </div> <p> <?php if ($get['doSearch'] == 'MLS Search') { $cond = ''; if($get['qoption'] == 'active') { $cond = "where `status`='ACTIVE' order by date desc"; } if($get['qoption'] == 'contingent') { $cond = "where `status`='CONTINGENT' order by date desc"; } if($get['qoption'] == 'pending') { $cond = "where `status`='PENDING' order by date desc"; } if($get['qoption'] == 'sold') { $cond = "where `status`='SOLD' order by date desc"; } if($get['qoption'] == 'resident') { $cond = "where `class`='Resident' order by price desc"; } if($get['qoption'] == 'farmland') { $cond = "where `class`='Farmland' order by price desc"; } if($get['qoption'] == 'commerical') { $cond = "where `class`='Commerical' order by price desc"; } if($get['qoption'] == 'other') { $cond = "where `class`='Other' order by price desc"; } //if($get['qoption'] == '') { if($get['q'] == '') { $sql = "select * from listings order by price asc"; // $sql = "select * from listings $cond"; // } } else { $sql = "select * from listings where `price` = '$_REQUEST[q]' or `mls`='$_REQUEST[q]' or `seller`='$_REQUEST[q]' or `class`='$_REQUEST[q]' or `status`='$_REQUEST[q]' order by `price` asc"; //$sql1="select * from images where `mls`='$sql'"; //$sql2="select * from agents where `tag`='$sql'"; // $sql = "select * from listings where `mls`='$_REQUEST[q]' or `price`='$_REQUEST[q]'"; } //$rs_total1=mysql_query($sql1) or die(mysql_error()); $rs_total = mysql_query($sql) or die(mysql_error()); $total = mysql_num_rows($rs_total); // $total1=mysql_num_rows($rs_total1); if (!isset($_GET['page']) ) { $start=0; } else { $start = ($_GET['page'] - 1) * $page_limit; } $rs_results = mysql_query($sql . " limit $start,$page_limit") or die(mysql_error()); $total_pages = ceil($total/$page_limit); // $rs_results1 = mysql_query($sql1 ."limit $start,$page_limit") or die (mysql_error()); ?> <?php // outputting the pages if ($total > $page_num_limit) { echo "<table width='81%' border='0' align='center' cellpadding='2' cellspacing='0' background='#fcfcdd'><span class='subHeader'><center>Pages: "; $i = 0; while ($i < $page_num_limit) { $page_no = $i+1; $qstr = ereg_replace("&page=[0-9]+","",$_SERVER['QUERY_STRING']); echo "<a href=\"listingsearch.php?$qstr&page=$page_no\">$page_no</a> "; $i++; } echo "</span></td></table>"; } ?> <? //while ($rrows3 = mysql_fetch_array($rrows3)){ ?> <form name "searchform" action="listingsearch.php" method="post"> </form> </table> <?php ////////////////////////////////////////////////////////////////////////////// while ($rrows = mysql_fetch_array($rs_results)) { $rrows2=mysql_fetch_array($sqlimages); $rrows3=mysql_fetch_array($sqlagents); /////////////////////////////////////////////////////////////////////////////// //$imagenamevar=($rrows['mls']=$rrows2['mls']); //echo $rrows3['id']; //$agentpicvar=($rrows['seller']=$rrow3['tag']); ?> <tr> <table width="81%" border="0" align="center" cellpadding="2" cellspacing="0" background="#fcfcdd"> <? echo $rrows['agents'.'seller_id'];?> <td width="161" height="211" align="center" valign="top" bgcolor="#fcfcdd"><div align="center"><img src="http://www.carneyrealty.com/newsite/uploads/<?php echo $rrows['mls'];?>/<? echo $mainimagevar; ?> width="214" height="160" /> </p> </div> <p class="tagline">Click for Additional Pictures</p></td> <td width="568" align="center" valign="top" bgcolor="#fcfcdd" class="calendarText"><div align="left"> <table width="592" height="180" border="1"> <tr valign="top"> <td width="74" height="27" bgcolor="#fcfcdd" class="tagline">Location </td> <td width="249" bgcolor="#fcfcdd"><strong><?php echo $rrows['location'];?> <br> <? echo $rrows['location1'];?> <br> <? echo $rrows3['tag'];?> </strong></td> <td width="180" rowspan="2" bgcolor="#fcfcdd" class="tagline"><div align="center"> <table width="180" height="62" border="1"> <tr valign="top"> <td width="70" rowspan="2" class="tagline"><a href="http://www.carneyrealty.com/newsite/upload/<?php echo $rrows['mls'];?>/<? echo "SD_disp.pdf";?>"><img align="absbottom" src="http://www.carneyrealty.com/newsite/Listing_pages/images/datasheet_018.jpg" width="58" height="50" /></a></td> <td width="50" class="tagline"><div align="left">Status </div></td> <td width="68"><div align="right" class="subHeader"><?php echo $rrows['status']; ?></div></td> </tr> <tr valign="top"> <td height="24" class="tagline"><div align="left">PRICE</div></td> <td align="center" valign="top"><div align="right"><strong class="subHeader"><?php echo $rrows['price']; ?></strong></div></td> </tr> </table> <span style="color: #fcfcdd"><strong><a href="mailto:<? echo $rrows['selleremail'];?>"><img src="http://www.carneyrealty.com/newsite/Listing_pages/images/mail_004.gif" width="14" height="15" /><? echo $rrows['seller'];?></a></strong></span></div></td> <td width="61" rowspan="2" bgcolor="#fcfcdd" class="tagline"><div align="right"></div> <span style="color: #fcfcdd"><img src="<? ///////////////////////////////////////////////////////////// while ($rrows3=($rrows['seller']=$rrows3['seller_id'])){ echo $rrows3['agentimage']; } ////////////////////////////////////////////////////////////// ?>" width="60" height="91" /></a></span></td> </tr> <tr valign="top"> <td height="64" bgcolor="#fcfcdd" class="tagline">Specs</td> <td bgcolor="#fcfcdd"><strong><?php echo $rrows['specs']; ?></strong></td> </tr> <tr valign="top"> <td height="77" bgcolor="#fcfcdd" class="tagline">Description</td> <td colspan="3" bgcolor="#fcfcdd" ><strong>MLS #<?php echo $rrows['mls'];?><br> <? echo $rrows['description'];?></strong> <p><strong>Call <? echo $rrows['seller'];?> at <? echo agentnumbervar;?> to view or for more information.</strong></p></td> </tr> </table> <tr> <td height="18" colspan="2" align="center" valign="top" bgcolor="#FF9933"><span class="bodyText style2" style="color: #fcfcdd"></span><span class="bodyText style2">S Carney & Associates Real Estate Brokerage 800 757 5783 </span></td> </tr> </div></td> </tr> </span> <? } ?> <td height="4"></td> </table> <? } ?> <? //} ?> </tr> <?php // outputting the pages if ($total > $page_limit) { echo "<table width='81%' border='0' align='center' cellpadding='2' cellspacing='0' background='#fcfcdd'><span class='subHeader'><center>Pages: "; $i = 0; while ($i < $page_num_limit) { $page_no = $i+1; $qstr = ereg_replace("&page=[0-9]+","",$_SERVER['QUERY_STRING']); echo "<a href=\"listings.php?$qstr&page=$page_no\">$page_no</a> "; $i++; } echo "</span></td></table>"; } ?> </td> </tr> <tr> <td height="22" class="bodyText"><? include 'footer1.shtml'; ?> </td> </tr> <tr> <td height="194" class="bodyText"><div align="center"> <table width="513" border="0"> <tr valign="top"> <th width="94" scope="col"><div align="center"><a href="http://www.realtor.org/technology/crt_secure/home?opendocument"><img src="images/index.1.gif" width="43" height="42" border="0" /></a></div></th> <th width="46" scope="col"><div align="center"></div></th> <th width="100" valign="middle" scope="col"><div align="center" class="style7"> <div align="center"><a href="http://www.nacogdochesmls.com/nag/passwd.php"><img src="images/MLS_a_94-50.gif" width="92" height="51" alt="Multiple Listing Service" /></a></div> </div></th> <th width="119" scope="col"><div align="center"><a href="http://www.hud.gov/offices/fheo/FHLaws/"><img src="http://www.habitatwhitley.org/equal_housing_logo.jpg" alt="Equal Housing Opportunity" width="60" height="62" border="0" /></a></div></th> <th width="129" scope="col"><div align="center"></div></th> </tr> <tr valign="top"> <td height="32"><div align="center" class="style8"><a href="http://www.realtor.org/technology/crt_secure/home?opendocument">REALTOR.ORG</a></div></td> <td><div align="center"></div></td> <td valign="middle"><div align="center"><span class="style10"><a href="http://www.nacogdochesmls.com/nag/passwd.php">Multiple Listing System</a></span></div></td> <td><div align="center"><strong><a href="http://www.hud.gov/offices/fheo/FHLaws/">Equal Housing Opportunity</a></strong></div></td> <td><div align="center"><a href="http://www.bbb.org/">BETTER BUSINESS BUREAU</a></div></td> </tr> </table> </div></td> </tr> </table> <div align="left"> <br /> </div> </div> </td> <td valign="top"><div align="left"></div></td> <td width="4"><div align="left"></div></td> </tr> <tr> <td width="15"> </td> <td width="35"> </td> <td width="698"><div align="center"> <?php include 'footer.shtml'; ?> </div> </td> <td width="1"><div align="center"></div></td> <td width="4"> </td> </tr> </table> </table> </table> </div> </body> </html> Hi the file file upload whenever i upload an image to main directory it saves one image into photos folder and copy another into thumbs folder but whenever i upload image to a different album (not main directory) it doesnt copy the other image to thumbs folder what i'm i doing wrong this is the line that i chose the folder... function make_locations ($locs) { $html = '<select name="locations" class="input"><option value="0">-- Main Directory --</option>'; foreach ($locs AS $key => $value) { $html .= '<option value="' .$value['album_id']. '">' .addslashes($value['album_name']). '</option>'; } $html .= '</select>'; return $html; } this is the whole code <?php /** * create a sub album directory for photos * to be stored in */ function create_album ($album_name, $sub_album = 0) { global $db; $sql = "INSERT INTO " .ALBUMS_TABLE. " ( album_name, sub_album ) VALUES ( '" .addslashes($album_name). "', " .intval($sub_album). " )"; if ($db->query($sql)) { return TRUE; } else { return FALSE; } } /** * get a list of sub albums */ function get_albums ($sub_album = 0) { global $db; $sql = "SELECT * FROM " .ALBUMS_TABLE. " WHERE sub_album = " .intval($sub_album); $db->query($sql); // initialise album storage $albums = array(); while ($row = $db->fetch()) { $albums[] = $row; } return $albums; } /** * get a list of photos within an album */ function get_photos ($album = 0) { global $db; $sql = "SELECT * FROM " .PHOTOS_TABLE. " WHERE album_id = " .intval($album). " ORDER BY photo_id ASC"; $db->query($sql); // initialise album storage $photos = array(); while ($row = $db->fetch()) { $photos[] = $row; } return $photos; } /** * get a large version of a particular photo */ function get_large ($photo, $album = 0, $next = '') { global $db, $template, $account_details; // shall we get the next / previous photo switch ($next) { case "next" : $next_sql = "AND photo_id > " .intval($photo). " ORDER BY photo_id ASC"; break; case "previous" : $next_sql = "AND photo_id < " .intval($photo). " ORDER BY photo_id DESC"; break; default : $next_sql = "AND photo_id = " .intval($photo); break; } $sql = "SELECT * FROM " .PHOTOS_TABLE. " WHERE album_id = " .intval($album). " " .$next_sql. " LIMIT 1"; $db->query($sql); if ($db->num_rows() == 0) { return ''; } else { $photo_info = $db->fetch(); // note the total directory $location = 'photos/' .$photo_info['photo_proper']; // now we need to resize list($width, $height) = getimagesize($location); if ($width < 300) { $new_width = $width; $new_height = $height; } elseif ($width > $height) { $new_width = 300; $new_height = $height * ($new_width / $width); } elseif ($width < $height) { $new_width = $width * ($new_height / $height); $new_height = 300; } // work out the next link $next = '<a href="portfolio.php?p=' .$photo_info['photo_id']. '&a=' .$photo_info['album_id']. '&next=next">Next</a>'; $previous = '<a href="portfolio.php?p=' .$photo_info['photo_id']. '&a=' .$photo_info['album_id']. '&next=previous">Previous</a>'; return '<div id="largephoto"><img src="' .$location. '" height="' .$new_height. '" width="' .$new_width. '" class="large"><br /><div id="prevnext">' .$previous. ' :: ' .$next. '</div></div>'; } } /** * get an array of locations */ function get_locations () { global $db; // initialise array $locations = array(); // select albums $sql = "SELECT album_id, album_name FROM " .ALBUMS_TABLE; $db->query($sql); while ($row = $db->fetch()) { $locations[] = $row; } return $locations; } /** * make the locations table */ function make_locations ($locs) { $html = '<select name="locations" class="input"><option value="0">-- Main Directory --</option>'; foreach ($locs AS $key => $value) { $html .= '<option value="' .$value['album_id']. '">' .addslashes($value['album_name']). '</option>'; } $html .= '</select>'; return $html; } /** * delete an album from the database * does not delete the photos in it */ function delete_albums ($album_ids) { global $db; if (sizeof($album_ids) > 0) { $sql = "DELETE FROM " .ALBUMS_TABLE. " WHERE album_id IN (" .implode(',', $album_ids). ")"; if ($db->query($sql)) { return TRUE; } } return FALSE; } /** * delete a set of photos */ function delete_photos ($photo_ids) { global $db; if (sizeof($photo_ids) > 0) { // select photo names for deletion $sql = "SELECT photo_proper FROM " .PHOTOS_TABLE. " WHERE photo_id IN (" .implode(',', $photo_ids). ")"; $db->query($sql); $unlink_ids = array(); while ($row = $db->fetch()) { $unlink_ids[] = $row['photo_proper']; } // now delete the photos if (sizeof($unlink_ids) > 0) { $sql = "DELETE FROM " .PHOTOS_TABLE. " WHERE photo_id IN (" .implode(',', $photo_ids). ")"; if ($db->query($sql)) { // remove photo from directory for ($i = 0; $i < sizeof($unlink_ids); $i++) { unlink("photos/" .$unlink_ids[$i]); unlink("photos/thumbs/" .$unlink_ids[$i]); } return TRUE; } } } return FALSE; } /** * upload a set of files */ function upload_files ($save_dir = '', $album = 0) { global $db; // check the save dir is writable if (!is_writable($save_dir)) { return FALSE; } // specify allowed file types $allowed_types = array ( 'image/jpg', 'image/jpeg', 'image/pjpeg', 'image/gif' ); // keep a list of uploaded files $uploaded = array(); // store bytes uploaded $total_bytes = 0; // go through the list of files while (list($key, $value) = each($_FILES['userfile']['name'])) { // check file has been passed if (!empty($value)) { // find extension $extension = substr($_FILES['userfile']['name'][$key], strpos($_FILES['userfile']['name'][$key],".") + 1); // time + $key for name $name = time(). "_" .$key. "." .$extension; // save url $add = $save_dir. "/" .$name; if (move_uploaded_file($_FILES['userfile']['tmp_name'][$key], $add)) { chmod($add, 0777); // add photo to database create_photo($_FILES['userfile']['name'][$key], $name, $album); } } } return TRUE; } /** * insert photo details into the database */ function create_photo ($photo_name, $key_name, $album = 0) { global $db; // get the filesize if (!$size = filesize("photos/" .$key_name)) { $size = 0; } // insert the photo in the database $sql = "INSERT INTO " .PHOTOS_TABLE. " ( photo_name, photo_date, photo_proper, photo_size, album_id ) VALUES ( '" .addslashes($photo_name). "', " .time(). ", '" .addslashes($key_name). "', " .intval($size). ", " .$album. " )"; if ($db->query($sql)) { return TRUE; } else { return FALSE; } } /** * get a complete raw copy of the directory */ function get_dir_contents ($dir) { // declare content array $contents = array(); // check gallery exists if (is_dir($dir)) { if ($handle = opendir($dir)) { while (FALSE !== ($file = readdir($handle))) { if ($file != '.' && $file != '..' && $file != 'thumbs') { if (file_exists($dir. '/thumbs/' .$file) || thumbnail($file, $dir. '/' .$file, $dir. '/thumbs')) { $contents[] = $dir. '/thumbs/' .$file; } else { $contents[] = 'no_image.gif'; } } } } } return $contents; } /** * create a thumbnail of a photo and store it * in the thumbs directory */ function thumbnail ($filename, $source_file, $destination, $new_h = 75, $new_w = 75) { if (!is_file($source_file)) { return FALSE; } // get the image details list($old_w, $old_h, $type) = getimagesize($source_file); // create source image switch($type) { case 1: $source = @imagecreatefromgif($source_file); break; case 2: $source = @imagecreatefromjpeg($source_file); break; case 3: $source = @imagecreatefrompng($source_file); break; default : return FALSE; } // work out dimensions if ($old_w < $old_h) { $thumb_w = $new_w; $thumb_h = $old_h * ($new_h / $old_w); } elseif ($old_w > $old_h) { $thumb_w = $old_w * ($new_w / $old_h); $thumb_h = $new_h; } elseif ($old_w == $old_h) { $thumb_w = $new_w; $thumb_h = $new_h; } $thumb = @imagecreatetruecolor($thumb_w, $thumb_h); // create image imagecopyresized($thumb, $source, 0, 0, 0, 0, $thumb_w, $thumb_h, $old_w, $old_h); // check we have a proper destination if (!is_dir($destination)) { mkdir($destination, 0777); } // save image switch ($type) { case 1: case 2: imagejpeg($thumb, $destination. '/' .$filename); break; case 3: imagepng($thumb, $destination. '/' .$filename); break; } // memory saving imagedestroy($thumb); imagedestroy($source); // thumbnail created successfully return TRUE; } /** * make the table to show the directories and photos */ function make_table ($list, $type, $row = 3) { // initialize gallery html array $gallery_html = array(); // check if we have a list > 0 if ($size = sizeof($list)) { switch ($type) { case "GALLERIES" : $gallery_html[] = '<div id="galleries">'; break; case "PHOTOS" : case "RAW" : $gallery_html[] = '<div id="photos">'; break; } // loop through list for ($i = 0; $i < sizeof($list); $i++) { // shall we open a new list if ($i % $row == 0) { $gallery_html[] = '<ul>'; } // add to list switch ($type) { case "GALLERIES" : // create the delete link $delete_link = ''; if ($_SESSION['logged_in']) { $delete_link = '[ <a href="admin.php?mode=deletealbum&a=' .$list[$i]['album_id']. '">Delete</a> ]'; } $gallery_html[] = '<a href=portfolio.php?albums='.$list[$i]['album_id'].'><img src="folder.gif" class="directory"><br />' .addslashes($list[$i]['album_name']). '</a><br />' .$delete_link. '</li>'; break; case "PHOTOS" : // construct photo name $name = $list[$i]['photo_proper']; // construct location $location = "photos/"; // create thumbnail if (!file_exists($location. "/thumbs/" .$name)) { thumbnail($name, $location. "/" .$name, $location. "/thumbs/"); } // construct date $date = '<div class="date">' .date("d/m G:ia", $list[$i]['photo_date']). '</div>'; // create the delete link $delete_link = ''; if ($_SESSION['logged_in']) { $delete_link = '[ <a href="admin.php?mode=deletephoto&p=' .$list[$i]['photo_id']. '">Delete</a> ]'; } // image information list($width, $height) = getimagesize($location . $list[$i]['photo_proper']); // add to the html $gallery_html[] = '<li><a href="' .$location . $list[$i]['photo_proper']. '" rel="lightbox[racing]" title="Photos"><img src="' .$location. "/thumbs/" .$name. '" class="picture"><br />View</a><br />' .$delete_link. '</li>'; break; case "RAW" : $gallery_html[] = '<li><img src="' .$list[$i]. '" class="picture"></li>'; break; } // shall we close the list if ( ($i + 1) % $row === 0 || ($i + 1) == $size) { $gallery_html[] = '</ul>'; } } $gallery_html[] = '</div>'; } return implode('', $gallery_html); } ?> Hey guys! I have the following doubt: I have a php file that does the following alongside with other code not displayed he $fp = fopen("emails.txt", "w"); It opens a txt file called emails.txt that is in the same folder where the php is saved but how do I tell $fp = fopen("/folderbefore/emails.txt", "w"); ?? In other words, how do I write the path on the script that the emails.txt is located in a previous folder where the php file is located?? Thanks in advance for your help Cheers! Hi, I want to be able to click on the photo and go to the next one in a folder. I have this code already, I just am not quite sure how to finish it. -George Code: [Select] <?php $count = $_GET['count']; $dir = "images"; $names = array(); $handle = opendir($dir); while ($name = readdir($handle)){ if(is_dir("$dir/$name")) { if($name != '.' && $name != '..') { echo "directory: $name\n"; } } elseif ($name != '.DS_Store' ) { $names[] = $name; } } closedir($handle); $numberofitems = count($names); $numberofitems--; if ($count <= $numberofitems){ echo "<p>"; echo "<img src='images/".$names[$count]."'>"; } else {echo "end";} ?> I made an upload image system, the images are stored in a folder, while the image name is stored in database. When I try to execute the image name, it works successfully, but when I try to disply the image from the folder by using the image name in the database, I fail each time. The folder where the images are being stored is named: saveimage Here is the query: Code: [Select] <?php mysql_connect('localhost', 'root', '') or die ('Connection Failed'); mysql_select_db('imagedatabase'); $images = mysql_query("SELECT * FROM img WHERE email='$lemail'"); while($row = mysql_fetch_array($images)) { echo "<img src='saveimage/'".$row['img_description']; } ?> Hey guys - I have some code that pulls an image out of a folder and displays it on the page. The problem is, there won't always be an image to display in which case I'd rather the code not even display. Here's my code so far: Code: [Select] <tr><td><a href="images/uploads/<?php echo $row['loc_id']; ?>_1.jpg"><img id="morephoto" src="images/uploads/thumbs/<?php echo $row['loc_id']; ?>_1thb.jpg" /></a></td></tr> The images are renamed on upload to have the id number for that row appended to the front of the file name and that is how I'm calling them back in. I know I need to write an if statement that contains the code from the <tr> to the </tr> to display if the image exists, the problem is, since there isn't a field for this in the database, I don't know how to check it? I'm still a noob so I appreciate any help that is offered. Thanks! Can someone tell me how I can remove or delete an image from a folder on a server using PHP? I tried this: Code: [Select] unlink("http://midwestcreativeconsulting.com/jhrevell/wp-content/themes/twentyten_3/upload/" . $location); before my delete MySQL statement, but I keep getting this error: Warning: unlink() [function.unlink]: http does not allow unlinking in /home/midwestc/public_html/jhrevell/wp-content/themes/twentyten_3/removejewelry.php on line 22 Can anyone help and tell me how I can make it work? I'm trying to write code that will let me pull 10 out of 15 images out of a folder and display them on my site. The images are all different, and I don't want dupes to show. So far, I have the following code figured out: --------------- $s = array ("image.jpg", "image2.jpg"); // as many images as you want $n = rand(1,len($s)); // randomly pick a number between 1 and the length of the array echo "<img src='". $s[$n] .'">"; // create an image tag for the randomly selected imagine (value of the randomly defined key) array_pop($s, $n); // This piece isn't right, it needs to EXTRACT and delete the $n array element. // Next random image $n = rand(1,len($s)); echo "<img src='". $s[$n] .'">"; --------------- Any ideas what array_pop should be to work properly? Thank you for the help! The problem: I'm trying to create a page which outputs images from a folder which I have been able to do, but the problem I'm having is not being able to get the page to display the most recent image according to file modification date at the top. The first set of code below outputs the image timestamps in descending order, from newest to oldest which is what I want, but as soon as I change/add a couple lines of code (Shown in the second lot of code) to get the image file name along with the timestamp, the echoed list (timestamp and file names) gets muddled up in a random order. In short; As soon as the file names are retrieved with the timestamp, the list goes from being organised descendingly, to not. Show timestamp only code (1st lot of code): <?php //Open images directory $ignore = array("..","."); $dir = opendir("images1"); $images = array(); $sortedimages = array(); //List files in images directory while (($file = readdir($dir)) !== false) if (!in_array($file, $ignore)) $images[] = $file; foreach ($images as $image) { $filetime = filemtime("images1/$image"); $sortedimages[] = $filetime; } rsort($sortedimages); foreach ($sortedimages as $sorted) { //foreach ($sorted as $key => $value) //{ echo "$sorted<br/>"; } //} closedir($dir); ?> The show timestamp and file name code (2nd lot of code): <?php //Open images directory $ignore = array("..","."); $dir = opendir("images1"); $images = array(); $sortedimages = array(); //List files in images directory while (($file = readdir($dir)) !== false) if (!in_array($file, $ignore)) $images[] = $file; foreach ($images as $image) { $filetime = filemtime("images1/$image"); $sortedimages[] = array($filetime => $image); } rsort($sortedimages); foreach ($sortedimages as $sorted) { foreach ($sorted as $key => $value) { echo "$key and $value<br/>"; } } closedir($dir); ?> The changes made in the 2nd script from the 1st: //Changed: $sortedimages[] = $filetime; ---> $sortedimages[] = array($filetime => $image); //Included the previously commented out: foreach ($sorted as $key => $value) { } //Changed: echo "$sorted<br/>"; ---> echo "$key and $value<br/>"; Thanks for any help! Hi I am trying to create a dynamic gallery in php with specific order of pictures on the page, but I can't find the function or piece of php code to do so.
Conditions: My code: $files = glob("layout/gallery/*.jpg"); rsort($files, SORT_NATURAL); for ($i=0; $i < count($files); $i++) { for( ; $i<5; $i++){ $one = $files[$i]; echo '<img src="'.$one.'">' . '<br><br>'; } echo "<br>"; for( ; $i<9; $i++){ $two = $files[$i]; echo '<img src="'.$two.'">' . '<br><br>'; } } The code works well, but it just displays 9 pictures obviously. I was unable to make it dynamic displaying 5 pictures first, 4 pictures after and stay this way in a loop till displays all pictures from that folder. I have searched around and found this code that suggests that I should be able to read an image file and echo it directly in to the page without hyperlinking to the file that is outside the public folder, but i get the error message that it is not there even though the file is. Warning: getimagesize() [function.getimagesize]: Unable to access "/home/****/upload/AAABBBCCC.JPG" in /home/****/public_html/client.php on line 40 Code: [Select] $image = "AAABBBCCC.JPG"; $path= "/home/****/upload/"; $details = getimagesize($path . $image); header ('Content-Type: ' . $details['mime']); echo file_get_contents($path . $image); Hi
I echo out images from a folder. The problem is that I have a html file in the same folder but I don't want to echo that out. How can I write my code to get rid of the html in the output?
Here my code:
<?php $filetype = '*.html'; $dirname = substr('$filetype'); $i=0; if (isset($_POST['submit2'])) { //get the dir from POST $selected_dir = $_POST['myDirs']; //now get the files from within the selected dir and echo them to the screen foreach(glob($selected_dir . DIRECTORY_SEPARATOR . '*') as $dirname) { echo substr($dirname, 0, -4); echo '<img src="'.$dirname.'" />'; echo "<label><div class=\"radiobt\"><input type='radio' name='radio1' value='$i'/></div></label>"; } } ?>P.S. when I echo out : substr($dirname, 0, -4); I want to get ride of the html filename there too. How can I do so something like this? Hi Basically I've built a CMS where by my clients can upload a number of images. On the success page I want to display the images they uploaded by file name. The issue is the number of images can vary. They may upload 2 or 10 or 50 etc. So far I've come up with this: Code: [Select] // number of files $UN = 3; //I've set this to 3 for now, but this is passed from the upload page! // server directories and directory names $dir = '../properties'; $images = glob($dir.'/*.{jpg}', GLOB_BRACE); //formats to look for $num_of_files = $UN; //number of images to display from number of uploaded files foreach($images as $image) { $num_of_files--; $newest_mtime = 0; $image = 'BROKEN'; if ($handle = @opendir($dir)) { while (false !== ($file = readdir($handle))) { if (($file != '.') && ($file != '..')) { $mtime = filemtime("$dir/$file"); if ($mtime > $newest_mtime) { $newest_mtime = $mtime; $image = "$file"; } } } } if($num_of_files > -1) //this made me laugh when I wrote it echo $trimmed = ltrim($image, "../properties").'<br />'; //display images else break; } Without this piece of code: Code: [Select] $newest_mtime = 0; $image = 'BROKEN'; if ($handle = @opendir($dir)) { while (false !== ($file = readdir($handle))) { if (($file != '.') && ($file != '..')) { $mtime = filemtime("$dir/$file"); if ($mtime > $newest_mtime) { $newest_mtime = $mtime; $image = "$file"; } } } } It shows the first 3 files alphabetically. I want to view the last number of images added. With the above code it simply shows the last image added 3 times! So I need to get the time each image was added and then order by the newest added and limit to the number of images uploaded. Any suggestions please? Kindest regards Glynn Basically i have a folder with 100+ images they are NOT all the same extension, what im wanting to do is use PHP to find all the images and put them all in a database. how would i go about doing this? thanks Hey guys, i'm new to this site and would need some help with coding. So i'm making a car part website which should has brand/model search. It's a dropdown search which will get the brand / model from database and should display all the parts for that exact model, from folder. Database structure which i have is id, master, name. ( Here's some pictures to clear out what i'm doing. http://imgur.com/a/7XwVd ) So the problem is that it does not get the images from folder named ex: *_audi_a3.jpg. And link to codes what have been written already. Parts.php: http://pastebin.com/q6vdypge Update.php: http://pastebin.com/DymhGQ17 Search_images.php: http://pastebin.com/LF5Q0i8f Core.js: http://pastebin.com/bgc0y4TS I don't know what's wrong with it sadly. One thing i noticed when i used firebug it gives error on category when searching error:true. Hope you guys understand what i mean here, and also all help is appreciated. And move this post if it's in wrong place. Thanks! Edited by aeonius, 17 October 2014 - 12:15 PM. I am attempting to us glob to display contents of a users folder using a session variable. Example: I have a session variable called department Code: [Select] $row_fullname['department']; In department I have the name of the department the user belongs to such as: office, plant, maintenance, and groundskeeping I created a folder called docs inside of docs there are 4 subfolders called office, plant, maintenance, and groundskeeping I found this code which will display the contents of the folder: Code: [Select] <?php $files = glob( './docs/office/*.*' ); foreach ( $files as $file ) { echo '<a href="./docs/office/' . basename( $file ) . '"target="_blank">' . basename( $file ) . '</a><br />'; } ?> The above code works fine, but I would like it to only display the contents of a departments folder only if the user is part on that department. Here is an example that I know is completely wrong but it may help explain what I am trying to do. Code: [Select] <?php ]<?php $files = glob( './docs/echo $row_fullname['department'];/*.*' ); foreach ( $files as $file ) { echo '<a href="./docs/echo $row_fullname['department'];/' . basename( $file ) . '"target="_blank">' . basename( $file ) . '</a><br />'; } ?>Thanks for your time |