PHP - Display Uploaded Images
Hi everyone!!
I have looked into how the upload script works and this is what i have: Code: [Select] <?php if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/pjpeg")) && ($_FILES["file"]["size"] < 20000)) { if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; } else { echo "Upload: " . $_FILES["file"]["name"] . "<br />"; echo "Type: " . $_FILES["file"]["type"] . "<br />"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />"; echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />"; if (file_exists("upload/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]); echo "Stored in: " . "upload/" . $_FILES["file"]["name"]; } } } else { echo "Invalid file"; } ?> Which is un-tested at the moment, but let's just say for talking sake it worked 100% what elements of this script would i be looking at to display the files uploaded on to another page, in my case my homepage? ive found as to yet, that the uploads have to be stored on a file somewhere on my server, which i've set up. But i thought it would be just as easy to have a field in my table named upload and display it within the table next to the other results? instead i just get whatever the file name is named.jpg. Any help in looking towards the answer? many thanks in advance guys! Similar TutorialsHi everyone, I am after a scrpit/function that will get information of an uploaded image, resize it, then display the manipulated image. in my "upload" script, there will be a size limit and a file extension/type limit to: 600 x 200px / jpg, gif, jpeg... this is to keep the script i'm after more simple. As using vector images i'm told is such a complicated problem for me at this time. So... to get the size info/dimensions its like this: Code: [Select] <?php list($width, $height, $type, $attr) = getimagesize("image_name.jpg"); echo "Image width " .$width; echo "<BR>"; echo "Image height " .$height; echo "<BR>"; echo "Image type " .$type; echo "<BR>"; echo "Attribute " .$attr; ?> and..... resize something like this: Code: [Select] function get_image_sizes($sourceImageFilePath, $maxResizeWidth, $maxResizeHeight) { // Get width and height of original image $size = getimagesize($sourceImageFilePath); if($size === FALSE) return FALSE; // Error $origWidth = $size[0]; $origHeight = $size[1]; // Change dimensions to fit maximum width and height $resizedWidth = $origWidth; $resizedHeight = $origHeight; if($resizedWidth > $maxResizeWidth) { $aspectRatio = $maxResizeWidth / $resizedWidth; $resizedWidth = round($aspectRatio * $resizedWidth); $resizedHeight = round($aspectRatio * $resizedHeight); } if($resizedHeight > $maxResizeHeight) { $aspectRatio = $maxResizeHeight / $resizedHeight; $resizedWidth = round($aspectRatio * $resizedWidth); $resizedHeight = round($aspectRatio * $resizedHeight); } // Return an array with the original and resized dimensions return array($origWidth, $origHeight, $resizedWidth, $resizedHeight); } // Get dimensions $sizes = get_image_sizes($sourceImageFilePath, $maxResizeWidth, $maxResizeHeight); $origWidth = $sizes[0]; $origHeight = $sizes[1]; $resizedWidth = $sizes[2]; $resizedHeight = $sizes[3]; // Create the resized image $imageOutput = imagecreatetruecolor($resizedWidth, $resizedHeight); if($imageOutput === FALSE) return FALSE; // Error condition // Load the source image $imageSource = imagecreatefromjpeg($sourceImageFilePath); if($imageSource === FALSE) return FALSE; // Error condition $result = imagecopyresampled($imageOutput, $imageSource, 0, 0, 0, 0, $resizedWidth, $resizedHeight, $origWidth, $origHeight); if($result === FALSE) return false; // Error condition // Write out the JPEG file with the highest quality value $result = imagejpeg($imageOutput, $outputPath, 100); if($result === FALSE) return false; // Error condition And.... display is this: Code: [Select] <?php $database="***"; mysql_connect ("***", "***", "***"); @mysql_select_db($database) or die( "Unable to select database"); $result = mysql_query( "SELECT company_name, location, postcode, basicpackage_description, premiumuser_description, upload FROM Companies" ) or die("SELECT Error: ".mysql_error()); $num_rows = mysql_num_rows($result); print "\n\n\nThere are $num_rows records.<P>"; echo "<table><tr><th>Comppany Name</th><th>Location</th><th>Postcode</th><th>Basic Members</th><th>Upgraded Users</th><th>Company Logo</th></tr><tr><td></td><td></td><td></td><td></td><td></td><td></td></tr>";// store the records into $row array and loop through while ( $row = mysql_fetch_array( $result, MYSQL_ASSOC ) ) { // Print out the contents of the entry echo "<tr><td>{$row['company_name']}</td>"; echo "<td>{$row['location']}</td>"; echo "<td>{$row['postcode']}</td>"; echo "<td>{$row['basicpackage_description']}</td>"; echo "<td>{$row['premiumuser_description']}</td>"; echo "<td><img src=\"http://www.removalspace.com/images/COMPANIES{$row['upload']}\" alt=\"logo\" /></td></tr>";} echo "</table>"; ?> How will all these fit together in one script? any help i'd love it! many thanks in advance I have this script where it uploads the file name to a database plus a few more things. Main Upload form. (img_add.php) <form enctype="multipart/form-data" action="img_add.php" method="POST"> Name: <input type="text" name="name"><br> E-mail: <input type="text" name = "email"><br> Phone: <input type="text" name = "phone"><br> Photo: <input type="file" name="photo"><br> <input type="submit" value="Add"> </form> Uploader. (img_add.php) <?php //This is the directory where images will be saved $target = "mainnewsimg/"; $target = $target . basename( $_FILES['photo']['name']); //This gets all the other information from the form $name=$_POST['name']; $email=$_POST['email']; $phone=$_POST['phone']; $pic=($_FILES['photo']['name']); // Connects to your Database mysql_connect("localhost", "root", "") or die(mysql_error()) ; mysql_select_db("chat") or die(mysql_error()) ; //Writes the information to the database mysql_query("INSERT INTO `images` VALUES ('$name', '$email', '$phone', '$pic')") ; //Writes the photo to the server if(move_uploaded_file($_FILES['photo']['tmp_name'], $target)) { //Tells you if its all ok echo "The file ". basename( $_FILES['photo']['name']). " has been uploaded, and your information has been added to the directory"; } else { //Gives and error if its not echo "Sorry, there was a problem uploading your file."; } ?> And the one that views it. (img_view.php) It uses a get function so do it with img_view.php?img=2 <?php mysql_connect("localhost", "root", "") or die(mysql_error()) ; mysql_select_db("chat") or die(mysql_error()) ; //Retrieves data from MySQL $newsid = $_GET['img']; $data = mysql_query("SELECT * FROM `images` WHERE id ='$newsid'") or die(mysql_error()); //Puts it into an array while($info = mysql_fetch_array( $data )) { //Outputs the image and other data Echo "<img src=mainnewsimg/".$info['photo'] ."> <br>"; } ?> And my database sql. CREATE TABLE IF NOT EXISTS `images` ( `name` varchar(30) DEFAULT NULL, `email` varchar(30) DEFAULT NULL, `phone` varchar(30) DEFAULT NULL, `photo` varchar(30) DEFAULT NULL, `id` int(11) NOT NULL AUTO_INCREMENT, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ; -- -- Dumping data for table `images` -- INSERT INTO `images` (`name`, `email`, `phone`, `photo`, `id`) VALUES ('sdf', 'sdfdsdsf', 'dsffsfsdf', 'arrow_forward_last.gif', 1), ('sadd', 'sadd', 'adsadasdad', 'artbottomshadr.png', 2); The values inside I had to put in manually to test if it worked for the img_view.php Anyways, It doesnt want to upload the images at all, even tho it says it did and gives the message The file ". basename( $_FILES['photo']['name']). " has been uploaded, and your information has been added to the directory I would greatly appreciate some help, I also provided everything so you can try it on your own server too. Hi Everyone, I've been studying the topics at this site and others on ways to count uploaded images; and what I've tried hasn't worked. I have seen this question posed and answered many times and most of the answers are something akin to this: Code: [Select] $count = count($_FILES['userfile'] ['name']); echo "the number of photos is ".$count; The explanation usually states that "count($_FILES['userfile'])" will simply count the number of elements in the array and return 5. But including ['name'] will return the number of files (images) uploaded. I will allow up to five photos to be uploaded (less is OK too) and want to count them in order to iterate through the proper number of loops to filter and process the photos. I've tested both of the above and get 5 (elements) when I count the ['userfile']; but get 0 (zero) when I test "['userfile'] ['name']". Here's the html code: Code: [Select] <!-- html here to input form data --> <label></label><input type="hidden" name="MAX_FILE_SIZE" value="500000000" /><br /> <label for="userfile">Upload photo 1</label> <input type="file" name="userfile1" id="userfile1" /><br /> <label for="userfile">Upload photo 2</label> <input type="file" name="userfile2" id="userfile2" /><br /> <label for="userfile">Upload photo 3</label> <input type="file" name="userfile3" id="userfile3" /><br /> <label for="userfile">Upload photo 4</label> <input type="file" name="userfile4" id="userfile4" /><br /> <label for="userfile">Upload photo 5</label> <input type="file" name="userfile5" id="userfile5" /><br /><br /> <label></label><input type="submit" name="userfile" value="Send Ad" /> </form> I've been testing the uploads with two files (jpg) and have tried to come up with an alternative that can iterate through the file arrays and determine how many photos I have. The code I've been testing is as follows: Code: [Select] $num = 1; $count = 0; while ($num <=5) { foreach ($_FILES['userfile'.$num] as $upload){ if ($upload ['error'] != 4){ } $count ++; } $num++; } echo "the number of photos is ".$count; I'm using "['error'] !=4" because some times people won't have 5 photos to upload. The result I get is 25 or 5 (files) x 5 (elements) for a total of 25. Does anyone know the proper way of doing this? Thanks for you input! Cheers, Rick Please, I need help with resizing uploaded images. Copied below is the code for image upload ( which I tagged "upload.php") Code: [Select] <?php // define a constant for the maximum upload size define ('MAX_FILE_SIZE', 51200); if (array_key_exists('upload', $_POST)) { // define constant for upload folder define('UPLOAD_DIR', 'C:/upload_test/'); // convert the maximum size to KB $max = number_format(MAX_FILE_SIZE/1024, 1).'KB'; // create an array of permitted MIME types $permitted = array('image/gif', 'image/jpeg', 'image/pjpeg', 'image/png'); foreach ($_FILES['image']['name'] as $number => $file) { // replace any spaces in the filename with underscores $file = str_replace(' ', '_', $file); // begin by assuming the file is unacceptable $sizeOK = false; $typeOK = false; // check that file is within the permitted size if ($_FILES['image']['size'][$number] > 0 || $_FILES['image']['size'][$number] <= MAX_FILE_SIZE) { $sizeOK = true; } // check that file is of an permitted MIME type foreach ($permitted as $type) { if ($type == $_FILES['image']['type'][$number]) { $typeOK = true; break; } } if ($sizeOK && $typeOK) { switch($_FILES['image']['error'][$number]) { case 0: // check if a file of the same name has been uploaded // if (!file_exists(UPLOAD_DIR.$file)) { // move the file to the upload folder and rename it $success = move_uploaded_file($_FILES['image']['tmp_name'][$number], UPLOAD_DIR.$file); // } /* else { // get the date and time ini_set('date.timezone', 'Europe/London'); $now = date('Y-m-d-His'); $success = move_uploaded_file($_FILES['image']['tmp_name'][$number], UPLOAD_DIR.$now.$file); }*/ if ($success) { $result[] = "$file uploaded successfully"; } else { $result[] = "Error uploading $file. Please try again."; } break; case 3: $result[] = "Error uploading $file. Please try again."; default: $result[] = "System error uploading $file. Contact webmaster."; } } elseif ($_FILES['image']['error'][$number] == 4) { $result[] = 'No file selected'; } else { $result[] = "$file cannot be uploaded. Maximum size: $max. Acceptable file types: gif, jpg, png."; } } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Multiple file upload</title> </head> <body> <?php // if the form has been submitted, display result if (isset($result)) { echo '<ol>'; foreach ($result as $item) { echo "<strong><li>$item</li></strong>"; } echo '</ol>'; } ?> <form action="" method="post" enctype="multipart/form-data" name="multiUpload" id="multiUpload"> <p> <label for="image1">File 1:</label> <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo MAX_FILE_SIZE; ?>" /> <input type="file" name="image[]" id="image1" /> </p> <p> <label for="image2">File 2:</label> <input type="file" name="image[]" id="image2" /> </p> <p> <input name="upload" type="submit" id="upload" value="Upload files" /> </p> </form> </body> </html> This works fine , except that it only uploads to C:/upload_test instead of the images folder (../img/) Can you please help with the codes for creating thumbnails while retaining the original upload. Thanks My photo files are not being displayed in my table? They get sent to the mySQL database, then the server and it does grab all the other variables in the table and displays them, but the .jpg's are not shown, instead theres just the file name?? Code: [Select] <?php error_reporting(E_ALL); ini_set("display_errors", 1); echo '<pre>' . print_r($_FILES, true) . '</pre>'; //This is the directory where images will be saved $target = "/home/users/web/b109/ipg.removalspacecom/images/COMPANIES"; $target = $target . basename( $_FILES['upload']['name']); //This gets all the other information from the form $company_name=$_POST['company_name']; $basicpackage_description=$_POST['basicpackage_description']; $location=$_POST['location']; $postcode=$_POST['postcode']; $upload=($_FILES['upload']['name']); // Connects to your Database mysql_connect("server****", "username***", "password****") or die(mysql_error()) ; mysql_select_db("DB") or die(mysql_error()) ; //Writes the information to the database mysql_query("INSERT INTO `Companies` (company_name, basicpackage_description, location, postcode, upload) VALUES ('$company_name', '$basicpackage_description', '$location', '$postcode', '$upload')") ; echo mysql_error(); //Writes the photo to the server if(move_uploaded_file($_FILES['upload']['tmp_name'], $target)) { //Tells you if its all ok echo "The file ". basename( $_FILES['upload']['name']). " has been uploaded, and your information has been added to the directory"; } else { //Gives and error if its not echo "Sorry, there was a problem uploading your file."; } ?> "upload" is the variable that isnt displaying in my table how i want it to? Have you guys any ideas how to get it displayed correctly? Is it better to store uploaded images as 'content' in the database? (like he http://www.techsupportforum.com/forums/f49/tutorial-upload-files-to-database-176804.html).. Or just as a regular file which is referenced in the database..? Hi all, Could someone help me add a thumbnail script to the below that works on scaling it down to 200px x 133px. I guess it is not that hard. <?php $destination='aircraft/'.$reg."1.jpg"; $temp_file = $_FILES['image']['tmp_name']; move_uploaded_file($temp_file,$destination); ?> Thanks Right now users log in and upload an image to the website. I want every image that is uploaded to be watermarked with a particular logo. Is this possible? Any hints or tips will be appreciated. Thank you. Upload images - Thumbnail sizes? Hi all I haven't used php for a while now and I'm really stuck on some code I wrote and now I can't work how to change it. I have this function to upload images and create thumbnails. The thumbnails can be either landscape or portrait and I want them to have the same height. At the moment the portrait thumbnails height is equal to the landscape thumbnail width. The dimensions of the thumbnails are the same but the portrait images are portrait. How can I size the thumbnails so they all have the same height. Thanks in advance for any help or advice on this. Code: [Select] function upload_images(){ $photo_types = array('image/pjpeg'=>'.jpeg','image/jpeg'=>'.jpg','image/gif'=>'.gif','image/.bmp'=>'bmp','image/x-png'=>'.png'); //$number_of_uploads = 5; $image_Dir = "images_1/"; $image_thumb_Dir = $image_Dir . "thumbs/"; $photo_id_arr = array(); $photo_ext_arr = array(); $photo_id_ext_arr = array(); // if(isset($_FILES['images'])){ $image_uploaded = $_FILES['images']; for($i=0; $i<=count($_FILES['images']['name']);$i++){ if(!empty($image_uploaded['name'][$i])){ if(array_key_exists($image_uploaded['type'][$i], $photo_types)){ $file_temp = mysql_prep($image_uploaded['name'][$i]); // $query = "INSERT INTO photos (filename) VALUES ('{$file_temp}')"; $result = mysql_query($query); confirm_query($result); if($result){ $photo_id = mysql_insert_id(); array_push($photo_id_arr, $photo_id); } // $filetype = $image_uploaded['type'][$i]; $ext = $photo_types[$filetype]; array_push($photo_ext_arr, $ext); $dbfile_name = $photo_id . $ext; // $query = "UPDATE photos SET filename = '{$dbfile_name}' WHERE photo_id = '{$photo_id}'"; $result = mysql_query($query); confirm_query($result); // // $stored_image = $image_Dir . $dbfile_name; $stored_thumb = $image_thumb_Dir . $dbfile_name; move_uploaded_file($image_uploaded['tmp_name'][$i], $stored_image ); // $src_image = imagecreatefromjpeg($stored_image); // $src_width = imagesx($src_image); $src_height = imagesy($src_image); $new_width = 900; $new_height = 900; // if($src_width > $src_height){ $img_w = $new_width; $img_h = $src_height*($new_height/$src_width); } if($src_width < $src_height){ $img_w = $src_width*($new_width/$src_height); $img_h = $new_height; } if($src_width == $src_height){ $img_w = $new_width; $img_h = $new_height; } // $mainImg = imagecreatetruecolor($img_w, $img_h); imagecopyresampled($mainImg, $src_image,0,0,0,0,$img_w, $img_h, $src_width, $src_height); imagejpeg($mainImg, $stored_image, 100); imagedestroy($src_image); imagedestroy($mainImg); //*************************** // // // //*************************** $src_image = imagecreatefromjpeg($stored_image); // $src_width = imagesx($src_image); $src_height = imagesy($src_image); $new_width = 85; $new_height = 85; // if($src_width > $src_height){ $thumb_w = $new_width; $thumb_h = $src_height*($new_height/$src_width); } if($src_width < $src_height){ $thumb_w = $src_width*($new_width/$src_height); $thumb_h = $new_height; } if($src_width == $src_height){ $thumb_w = $new_width; $thumb_h = $new_height; } // $thumb = imagecreatetruecolor($thumb_w, $thumb_h); imagecopyresampled($thumb, $src_image,0,0,0,0,$thumb_w, $thumb_h, $src_width, $src_height); imagejpeg($thumb, $stored_thumb, 100); imagedestroy($src_image); imagedestroy($thumb); }else{ //echo "File format not supported."; } } } array_push($photo_id_ext_arr, $photo_id_arr); array_push($photo_id_ext_arr, $photo_ext_arr); return $photo_id_ext_arr; } } 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 hi to all.Im currently displaying the images from my upload directory but the image does not display.please help thanks Hi, this is what I want to get working: each time I add an entry, it is displayed in a nice html table, and each entry listed in this html table has an UPDATE link that allows the user to update the Price and Description field of the corresponding table in my database. I have also included an upload element which whenever a user chooses an image, it will replace the default fileUploadIcon.jpg with this. Please see the index.php and bellUpdateForm.php below respectively Code: [Select] //index.php <table border="border"> <?php require 'bellConnect.inc.php'; $curImage; $imgIndx=-1;//iniitally $result=mysql_query("SELECT ID, Name, Manufacturer, Price, Description, SimSupport FROM bellProducts"); $indx=0;//***HOW DO I MAKE THIS SHARED SO THAT EACH ENTRY ADDED HAS AN INCREMENTED index appended to end of its name attribute //phpinfo(); //print "Val of \$counter so far: ".$counter; //NB: print table headings if(mysql_num_rows($result))//if there is at least one entry in bellProducts, make a table { //$counter+=1; print "<table border='border'>"; print "<tr> <th>ID</th> <th>Image</th> <th>Name</th> <th>Manufacturer</th> <th>Price</th> <th>Description</th> <th>SimSupport</th> <th colspan=2 align='center'>Modify</th> </tr>"; //NB: now output each row of records while($row=mysql_fetch_assoc($result)) { //extract($row); //if($indx<sizeof($bellProductsArray)) //{ "<tr align='center'> <td>$row[ID]</td> <td>"; if($_POST['upload']) print "<img src=".$_FILES['image']['name'].">"; else print "<img src='fileUploadIcon.jpg' name='image' /> </td> <td> $row[Name] </td> <td> $row[Manufacturer] </td> <td> $$row[Price]</td> <td align='left'>$row[Description]</td> <td>$row[SimSupport]</td> <td><a href='bellUpdateForm.php?ID=$row[ID]'>UPDATE</a></td> <td><a href='bellDeleteForm.php?ID=$row[ID]' name='delete'>DELETE</a></td> </tr>"; //}//END INNER IF $indx++; }//END WHILE }//END BIG IF ?> </table> </body> </html> Code: [Select] //bellUpdateForm.php <?php require 'bellConnect.inc.php'; if($_GET && !$_POST)//this is to make sure that the current entry is selected BUT the updated info NOT submitted yet { if(isset($_GET['ID'])) { $ID=$_GET['ID']; $result=mysql_query("SELECT * FROM bellProducts WHERE ID=$ID"); $row=mysql_fetch_assoc($result); //store the one entry that will be updated print "You are currently updating item: <strong>$row[Manufacturer] $row[Name] </strong> <br /><br />"; "<form action='bellUpdate.php' method='post'> <label> Price:<input type='text' value='$row[Price]' name='price' id='price'></input> </label> <label> Description: <textarea cols='60' rows='3' name='description' id='description'> $row[Description] </textarea> </label> <div> <input type='submit' value='Update entry' name='update' id='update' /> <input type='hidden' value=$row[ID] name='id' /> </div> <input type='reset' value='Reset entry' />"; print "</form>"; }//END INNER IF }//END BIG IF ?> <form method='post' action='index.php' enctype='multipart/form-data' name='uploadImage' id='uploadImage'> <p> <label>Upload image</label> <input type='file' name='image' id='image' /> </p> <p> <input type='submit' value='Upload this' name='upload' id='upload' /> </p> </form> <?php if(array_key_exists('upload', $_POST)) { // define constant for upload folder define('UPLOAD_DIR', 'C:\wamp\www'); // move the file to the upload folder and rename it move_uploaded_file($_FILES['image']['tmp_name'], ! UPLOAD_DIR.$_FILES['image']['name']); } ?> </body> </html> I 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
I am looking to display image paths in a row separated by commas. There are 6 images that goes to each user and I would like only the 6 images at be in each " " Like this: "images/listings/listing_516013019A-only.jpg,images/listings/listing_848813453A-1.jpg,images/listings/listing_664613453A-2.jpg,images/listings/listing_520313453A-3.jpg,images/listings/listing_690513453A-4.jpg,images/listings/listing_125113453A-5.jpg,images/listings/listing_641013453A-6.jpg," "images/listings/listing_736913186A-1.jpg,images/listings/listing_822713186A-2.jpg,images/listings/listing_136513186A-3.jpg,images/listings/listing_700313186A-4.jpg,images/listings/listing_716013186A-5.jpg,images/listings/listing_213113186A-6.jpg," "images/listings/listing_292113254A..-1.jpg,images/listings/listing_854413254A..-2.jpg,images/listings/listing_446013254A..-3.jpg,images/listings/listing_676313254A..-4.jpg,images/listings/listing_563413254A..-5.jpg,images/listings/listing_341513254A..-6.jpg," Right now it is displaying them like this "images/listings/listing_516013019A-only.jpg," "images/listings/listing_848813453A-1.jpg," "images/listings/listing_664613453A-2.jpg," "images/listings/listing_520313453A-3.jpg," "images/listings/listing_690513453A-4.jpg," "images/listings/listing_125113453A-5.jpg," "images/listings/listing_641013453A-6.jpg," "images/listings/listing_736913186A-1.jpg," "images/listings/listing_822713186A-2.jpg," "images/listings/listing_136513186A-3.jpg," "images/listings/listing_700313186A-4.jpg," "images/listings/listing_716013186A-5.jpg," "images/listings/listing_213113186A-6.jpg," "images/listings/listing_292113254A..-1.jpg," "images/listings/listing_854413254A..-2.jpg," "images/listings/listing_446013254A..-3.jpg," "images/listings/listing_676313254A..-4.jpg," "images/listings/listing_563413254A..-5.jpg," "images/listings/listing_341513254A..-6.jpg," Here is the code I have: Code: [Select] <?php // Make a MySQL Connection mysql_connect("localhost", "xxxxxxxx", "xxxxxxxx") or die(mysql_error()); mysql_select_db("xxxxxxxx") or die(mysql_error()); $result = mysql_query("SELECT * FROM listimages ORDER BY listimages.listingid DESC ") or die(mysql_error()); while($row = mysql_fetch_array($result)) { echo "\""; echo "$row[imagepath],"; echo "\""; echo "<br>"; } ?> My tables for the images is "listimages" and the columns a id (which are the auto_increments) imagepath (which shows the path/image1.jpg) mainimage (which just shows 0 or 1 depending on the picture that is the default for that listing, 1 being default) listingid (shows numbers 1 2 3 etc corresponding to the Id in the listings table to show what images go with what listing) There are up to 6 images for each listing. Any idea how to fix this? I want to display thumbnails for a picture gallery and when user clicks on image the larger image opens in a new window. I can't find a straight answer on the php.net website. Can someone help? I read everywhere where it says not to stoe images in MYSQL but I have a code where I'm trying to display the images. They are all jpegs that are stored in the table. Here is the code Code: [Select] <?php include "dbaptsConfig.php"; include "searchaptsstyle.css"; // test id, you need to replace this with whatever id you want the result from $id = "1"; // what you want to ask the db $query = "SELECT * FROM `apartments` WHERE `id` = ".$id; // actually asking the db $res = mysql_query($query, $ms); // recieving the answer from the db (you can only use this line if there is always only one result, otherwise will give error) $result = mysql_fetch_assoc($res); // if you uncomment the next line it prints out the whole result as an array (prints out the image as weird characters) // print_r($result); // print out specific information (not the whole array) echo "<br/>"; echo "<div id='title'>".$result['title']."<br/></div>"; echo "<br/>"; echo "<div id='description'>".$result['description']."<br /></div>"; echo "<br/>"; echo "<div id='table'><tr>"; echo "<td bgcolor='#FFFFFF' style='color: #000' align='center'> Provider's Phone Number: ".$result['phone']."<br /></td>"; echo "<td bgcolor='#FFFFFF' style='color: #000' align='center'> Provider: ".$result['service']."<br /></td>"; echo "<td bgcolor='#FFFFFF' style='color: #000' align='center'> Borough: ".$result['county']."<br /></td>"; echo "<td bgcolor='#FFFFFF' style='color: #000' align='center'> Town: ".$result['town']."<br /></td>"; echo "<td bgcolor='#FFFFFF' style='color: #000' align='center'> Bedrooms: ".$result['rooms']."</td>"; echo "<td> </td>"; echo "<td bgcolor='#FFFFFF' style='color: #000' align='center'> Bathrooms: ".$result['bath']."<br /></td>"; echo "<td bgcolor='#FFFFFF' style='color: #000' align='center'> Square Footage: ".$result['square']."<br /></td>"; echo "<td bgcolor='#FFFFFF' style='color: #000' align='center'> Rent: ".$result['rent']."<br /></td>"; echo "<td bgcolor='#FFFFFF' style='color: #000' align='center'> Listed On: ".$result['time']."<br /></td>"; echo "</tr></div>"; header("Content-type: image/jpeg"); echo "<td bgcolor='#FFFFFF' style='color: #000' align='center'> Listed On: ".$result['image1']."<br /></td>"; ?> Thanks I'm creating a funeral home site and on the side of the page I would like to display the last 5 funeral obituaries that are in mySQL database (name and certain sized image (images are in "image" field) w/ a link to an "obituaries detail page for the individual deceased person"). I am able to do this successfully listing only the names....how can I list the image associated with the name? This is what I have so far: Code: [Select] <?php include("connect.php"); ?> Code: [Select] <?php $query = "SELECT id, deceased_name, deceased_date, DATE_FORMAT(deceased_date, '%M %D, %Y') as datetext"; $query .= " FROM scales_obits ORDER BY deceased_date DESC LIMIT 5"; $listings = mysql_query($query); if (!listings) { echo("<p>Error retrieving listings from lookup table<br>". "Error: " . mysql_error()); exit(); } echo("<table border=\"0\" width=\"100%\" class=\"obit\">"); while ($listing = mysql_fetch_array($listings)) { $deceased_name = $listing["deceased_name"]; $deceased_date = $listing["datetext"]; $id = $listing["id"]; echo("<tr><td width=\"100%\"><a href=\"obitdetail.php?id=".$id."\"><strong>".$deceased_name."</strong></a></td><td> </td>"); } echo("</table>"); ?> Hi I tried to write a script: 1) to locate all directories in a directory (1 level) 2) with the function GetImages() I try to display the image(s) in the subfolder there are only images in the subfolder I guess I'm doing something wrong in the GetImages() with the glob function, can anyone check this ? Thanks in advance function GetImages($map) { $files = glob('$map/*.jpg'); //$files = glob("$map/*.*"); for ($i=0; $i<count($files); $i++) { $num = $files[$i]; echo '<img height="50" width="50" src="'.$num.'" />'." <br />"; } } if ($handle = opendir('mystuff')) { /* loop through directory. */ while (false !== ($dir = readdir($handle))) { if($dir != ".." && $dir != "."){ echo '<option value='.$dir.'>'.$dir.'</option><br>'; GetImages($dir); } } closedir($handle); } I want to retrieve an image id from a db and show the images. I cant get the syntax right for the image tag.Any help appreciated. Code: [Select] function display_covers() { global $wpdb; $query = "select * from wp_cover"; $result = mysql_query($query)or trigger_error("Query: $query\n<br />MySQL Error: " . mysql_error()); echo mysql_error(); if (!$result) return false; echo'<div class="wrap"><p>choose from one of the covers below</p></div>'; echo'<div id="main">'; echo'<table class="main" cellpadding="2">'; //echo"<caption>Please choose a book cover</caption>"; ?> <thead><tr><td colspan="5" ><h6 class="main">Book Covers</h6></td></tr> </thead> <?php $i=0; $size=3; echo "<tbody>"; echo "<tr>"; while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) { /* display picture */ ?> <td class="main"> <?php echo"<img src="/Applications/MAMP/htdocs/wordpress_3/wp-content/plugins/Authors2/jackets/"{.$row['pix'].}""/>"; echo"</td>"; $i++; if($i==$size) { echo "</tr><tr>"; $i=0; } } } |