PHP - Retrieving All Images In A Folder Then Placing Them Into A Mysql Database
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 Similar TutorialsHi Everyone! Just learning php. Hope someone can help with this. Trying to design a product page of photo images with price, description, etc. At this point I am ignoring the design and just trying to get the fields to populate. They all work through my "while" loop except I cannot find the syntax for the image and am just getting the placeholder. My images are just "image".jpg in my root folder. Ex. building.jpg. And my table column is "picture_image". Appreciate any help. Here is the pertinent code which works fine except for the image $ROW. I have bolded the trouble block. Thanks! while($row = mysqli_fetch_assoc($result)) { // display row for each picture echo "<tr>\n"; echo " <td>{$row['Picture_ID']}</td>\n"; echo " <td style='font-weight: bold; font-size: 1.1em'>{$row['Picture_name']}</td>\n"; echo " <td>{$row['Picture_description']}</td>\n"; echo " <td>{$row['Picture_price']}</td>\n"; echo "<td><a href={$row['picture_image']}' border='0'> <img src='{$row['picture_image']}' border='0' width='100' height='80' /> </a></td>\n"; Hello Guys, I need help on this problem. output: display images for the values that exist in the table: input: the values in a table's column where they're in the format of "0,0" and the image corresponding to it is named 0,0.png this is my attempt $q is retrieving "0,0" however in order for me to retrieve its image i need to add ".png" to it in order to find it in the directory that the image is located. It tried without ".png" and it also doesn't work. $q = 'SELECT ID FROM table'; $dirname = "directory/"; $images = glob($dirname.$q.".png"); foreach($images as $image) { echo '<img src="'.$image.'" /><br />';
I am working on a kind of CMS for my own website which no one else will be using but me as a way of improving my php skills, and am having problems with retrieving data from the database that holds both text and php code. I have searched the web and found that i should be using eval() for the code to be executed before it is send to the browser but cannot get it to work and can't find my mistake(s). the php code will always be the same, and is supposed to retrieve the id number of a page to use in a link (and works fine when tested by loading the code directly without retrieving it from the database) this is an example of data stored in the database Code: [Select] The <a href="page_builder.php?id=<?php echo $page->id('mines_DwarvenMines') ?>">Dwarven Mines</a> have a great selection of Ores,... Of course when I leave it like this, hovering over the link in my page will show exactly that and lead to nowhere Code: [Select] localhost/page_builder.php?id=<?php echo $page->id('mines_DwarvenMines') ?> Most of these links appear in tips given at the end of the page and are processed as followed Code: [Select] $questtips = $quest->getQuestTips(); $tips = ""; if ($questtips == "none") { $tips = "/"; } else { foreach($questtips as $tip) { $tips .= "<li>"; $tips .= $tip->getTip(); $tips .= "</li>"; } } and finally put on screen by the presentation layer as followed Code: [Select] <h2>Tips & Extra Info</h2> <div class="tipsList"> <ul> <?php echo $tips ?> </ul> </div> I have tried all sorts to get the code to be executed when retrieved from the database before being send to the browser so that this particular link would say "localhost/page_builder.php?id=57" but I cannot get it to work, though I suspect it is fairly easy. I suspect I would have to store the data in a different format in the database? And how exactly do I use the eval() function in my case? Could someone please adjust my code so that it does work? 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. The subject could be a bit vague, but my problem is simple. (I think so) So I made a php test site that is quite similar to a forum. Where you see a title or a subject and when you click on it you will see more details about that subject. I made my database and script for inserting data into my mySQL database. I also did my output aswell, so every topic is posted on a webpage "archive" where you can see all the subjects. But now I want to see the full details of that type of subject by clicking on it. I have no idea how to make that happen googled it but didn't find any results...just wondering if it's even possible to do that. I'm a new guy here! Hi, here's my problem: I am trying to make a simple online buying website and I want to display a table with all the fields for each item. So I got that part down which is to just use mysql_fetch_assoc("SELECT * FROM myTable") and use the html table tags stuff, but now I want to display my images in the table, so here's my code to display my mysql database table in html's table tag along w/ php: <html> <head> <title>My Online buying website project</title> </head> <body> <?php mysql_connect("localhost","root"); mysql_select_db("myTable"); $imagesArray=array("Apple_iPhone3GS.jpg","Apple_iPhone4.jpg","product3.jpg","product4.jpg","product5.jpg"); $result=mysql_query("SELECT Name, Manufacturer, Price, Description, SimSupport FROM myTable"); if(mysql_num_rows($result))//if there is at least one entry in bellProducts, make a table { print "<table border='border'>"; print "<tr> <th>Name</th> <th>Manufacturer</th> <th>Price</th> <th>Description</th> <th>SimSupport</th> </tr>"; //NB: now output each row of records while($row=mysql_fetch_assoc($result)) { extract($row); print "<tr> <td>$Name</td> <td>$Manufacturer</td> <td>$Price</td> <td>$Description</td><td>$SimSupport</td> </tr>"; }//END WHILE }//END IF ?> </table> </body> </html> *So how do I go about adding my images in this table? 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 have this script called view.php Code: [Select] <?php include 'db.inc'; $file = clean($file, 4); if (empty($file)) exit; if (!($connection = @ mysql_pconnect($hostName, $username, $password))) showerror(); if (!mysql_select_db("Php_test", $connection)) showerror(); $query = "SELECT mime, data FROM file WHERE id = $file"; if (!($result = @ mysql_query ($query,$connection))) showerror(); $data = @ mysql_fetch_array($result); if (!empty($data["data"])) { // Output the MIME header header("Content-Type: {$data["mime"]}"); // Output the image echo $data["data"]; } ?>after i have db.inc Code: [Select] <?php // These are the DBMS credentials $hostName = "localhost"; $username = "root"; $password = "oxioxi"; // Show an error and stop the script function showerror() { if (mysql_error()) die("Error " . mysql_errno() . " : " . mysql_error()); else die("Could not connect to the DBMS"); } // Secure the user data by escaping characters // and shortening the input string function clean($input, $maxlength) { $input = substr($input, 0, $maxlength); $input = EscapeShellCmd($input); return ($input); } ?>and i have my page witch part of it is this Code: [Select] <?php include 'db.inc'; $query = "SELECT id, name, mime FROM file"; if (!($connection = @ mysql_pconnect($hostName, $username, $password))) showerror(); if (!mysql_select_db("php_test", $connection)) showerror(); if (!($result = @ mysql_query ($query, $connection))) showerror(); ?> <h1>Image database</h1> <?php if ($row = @ mysql_fetch_array($result)) { ?> <table> <col span="1" align="right"> <tr> <th>Short description</th> <th>File type</th> <th>Image</th> </tr> <?php do { ?> <tr> <td><?php echo "{$row["name"]}";?></td> <td><?php echo "{$row["mime"]}";?></td> <td><?php echo "<img src=\"view.php?file={$row["id"]}\">";?></td> </tr> <?php } while ($row = @ mysql_fetch_array($result)); ?> </table> <?php } // if mysql_fetch_array() else echo "<h3>There are no images to display</h3>\n"; ?>i have do it right but for some reason it doesnt displays the pictures the type and the name are displayed normally but not the picture!! instead of them there are small icons of not existing pictures.. please i want help i really need to do it I've searched all over and have found some scripts but none of them work anymore. Is there a way to fetch Google images using PHP? There's no Google Image API (only the regular Google API) Code: [Select] $query = mysql_query("SELECT a.*, b.* FROM friendlist a INNER JOIN friendlist b ON (a.friendemail=b.friendemail) INNER JOIN users c ON (b.friendemail = c.EmailAddress) WHERE a.email = 'asdf@gmail.com' AND c.Username LIKE '%carol%' GROUP BY a.id ORDER BY count(*) DESC"); Code: [Select] while ($showfriends = mysql_fetch_array($query)) { echo $showfriends['Username']; } and I would get nothing. It produces the correct number of <div> so i know it's getting through, but it's having trouble displaying the entries? I have my database set to insert the current time stamp when an entry is made into the table, I am then trying to retrieve via the following code: $select_view_idea="SELECT * FROM $tbl_name5 WHERE message_number='$message_number'"; $result_view_idea=mysql_query($select_view_idea); while($row_view_idea=mysql_fetch_assoc($result_view_idea)){ extract($row_view_idea); } date_default_timezone_set('US/Eastern'); $date=date('l, F jS Y h:i:s A T', $date); echo $date; The above is outputting: Wednesday, December 31st 1969 07:33:31 PM EST the database contains: 2011-11-18 00:47:56 Hey all, I've written a php search feature for a mysql database. The search returns a file name like sample.gif, how would I go about displaying the actual image instead? Since the images all have the same location could I have the search return the string into a variable then make the whole thing a link? Thanks. Hello people, currently i ran into some problem. Currently, i have a database called responses which have the fields of ID, Student_id, question_id, Answer. I had stored my results into the database which appeared to be 1 1 1 Agree 2 1 2 Disagree 3 3 4 Unsatisfied. So any recommendation on how should i do about in generating the result into a graph whereby the graph will show how many students choose "AGree" on that particular question THANKS Hi, I have managed to get the code working to store a .jpg file in the database under the longblob type. Now all i have left to do is to retrieve that image and display it. So far i have this: list.php Code: [Select] while($r = mysql_fetch_array($sql)) { //for each record ... echo " <img src= getoutside.php?id='".$r[apartmentId]. " '> "; getoutside.php Code: [Select] <?php header("Content-type: image/jpg"); // act as a jpg file to browser $nId = $_GET['id']; include 'dbase.php'; //connect to database $sqlo = "SELECT outside FROM apartment WHERE apartmentId = $nId"; $oResult = mysql_query($sqlo); $oRow = mysql_fetch_array($oResult); $sJpg = $oRow["outside"]; echo $sJpg; ?> The result from this is a box with a red cross in it. Can anyone find a problem with this code please? Thanks I have two tables. Table Name:Users Fields: User_name user_email user_level pwd 2.Reference Fields: refid username origin destination user_name in the users table and the username field in reference fields are common fields. There is user order form.whenever an user places an order, refid field in reference table will be updated.So the user will be provided with an refid Steps: 1.User needs to log in with a valid user id and pwd 2.Once logged in, there will be search, where the user will input the refid which has been provided to him during the time of order placement. 3.Now User is able to view all the details for any refid 3.Up to this we have completed. Query: Now we need to retrieve the details based on the user logged in. For eg: user 'USER A' has been provided with the referenceid '1234' during the time of order placement user 'USER B' has been provided with the referenceid '2468' during the time of order placement When the userA login and enter the refid as '2468' he should not get any details.He should get details only for the reference ids which is assigned to him. I have two tables. Table Name:Users Fields: User_name user_email user_level pwd 2.Reference Fields: refid username origin destination user_name in the users table and the username field in reference fields are common fields. There is user order form.whenever an user places an order, refid field in reference table will be updated.So the user will be provided with an refid Steps: 1.User needs to log in with a valid user id and pwd 2.Once logged in, there will be search, where the user will input the refid which has been provided to him during the time of order placement. 3.Now User is able to view all the details for any refid 3.Up to this we have completed. Query: Now we need to retrieve the details based on the user logged in. For eg: user 'USER A' has been provided with the referenceid '1234' during the time of order placement user 'USER B' has been provided with the referenceid '2468' during the time of order placement When the userA login and enter the refid as '2468' he should not get any details.He should get details only for the reference ids which is assigned to him. This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=318312.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=309239.0 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";} ?> |