473,800 Members | 2,475 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

view photos in a folder via the mysql

9 New Member
I have read and read about mysql, which I am sure is just like the quoted, "linux is very friendy, but it just chooses who it wants to be friends with..."

My first attempt to read the database in my forum actually works! Well, almost. It does query the correct places, lists the information, and I have even figured out how to see a full path to where the photo is stored.

But is never actually SHOWS the image.

My eventual goal is to simply input a member id# and it will list all of the photo attachments by that member.

Right now I would settle for it to work by displaying the photos found, (which does actually shows the path now, but not as a link or photo.) src and all that simply does not work, header ("Content-type: image/jpeg"); print $imagebytes;, fails as well, at least in any way I have tried.

Expand|Select|Wrap|Line Numbers
  1. <?
  2. $username="MyUserName";
  3. $password="MyPassWord";
  4. $database="MyDataBase";
  5. $x=date("j");
  6.  
  7. mysql_connect(localhost,$username,$password);
  8. @mysql_select_db($database) or die( "Unable to select database");
  9. $query="SELECT * FROM ibf_attachments";
  10. $result=mysql_query($query);
  11.  
  12. $num=mysql_numrows($result);
  13.  
  14. mysql_close();
  15.  
  16. echo "<b><center>Database Output</center></b><br><br>";
  17.  
  18. $i=0;
  19. while ($i < $num) {
  20.  
  21. $member=mysql_result($result,$i,"attach_member_id");
  22. $isimage=mysql_result($result,$i,"attach_is_image");
  23. $imagedate=mysql_result($result,$i,"attach_date");
  24. $imagesize=mysql_result($result,$i,"attach_filesize");
  25. $imagewidth=mysql_result($result,$i,"attach_img_width");
  26. $imageheight=mysql_result($result,$i,"attach_img_height");
  27. $imagelocation=mysql_result($result,$i,"attach_location");
  28.  
  29. // this sets the image location to a full path
  30. $full_location = "http://www.MySite.com/forum/uploads/$imagelocation";
  31.  
  32.  
  33.  
  34. echo "<b>$member $isimage</b><br>
  35. Image Date: $imagedate<br>
  36. Image Size: $imagesize<br>
  37. Image Width: $imagewidth<br>
  38. Image Height: $imageheight<br>
  39. location: $imagelocation  <br>
  40. <br><br>
  41.  
  42. // this actually shows the link, but not clickable, nor will it display image here.
  43. // I can copy and paste it in browser and it is correct path.
  44. full location: $full_location<br>
  45.  
  46. <hr><br>";
  47.  
  48. ?>
  49.  
  50. <?PHP
  51.  
  52. $i++;
  53. }
  54.  
  55. ?>


any help would be apprecitated!
Nov 29 '09 #1
22 4057
Dormilich
8,658 Recognized Expert Moderator Expert
if you want to display an image in HTML you have to use the <img> tag pointing to the picture, which may be either the file of the image or a script file, that fetches the image and returns the binary data.
Expand|Select|Wrap|Line Numbers
  1. // in HTML (image from DB)
  2. <img src="image.php?id= xyz" width="…" height="…" alt="…">
Expand|Select|Wrap|Line Numbers
  1. // image.php
  2. header("Content-Type: image/jpeg"); // or whatever image type you have
  3. // connect to DB
  4. // query DB for image (using $_GET)
  5. // return data:
  6. echo $image;
  7. // close DB
see also the Insights Article Uploading files into a MySQL database using PHP (chapter 4)

PS. the only functions/packages that can fetch the whole result set into an array are PDO and MySQLi, both available in PHP 5 …
Nov 29 '09 #2
skysober
9 New Member
thanks. I appreciate your attempt to assist, It doesn't help me, as I do not understand it, but I appreciate it. (and I do have php5 on the server)

I need to know how to make $imagelocation in the above PHP file show as a photo, not a non-clickable link.
Nov 30 '09 #3
Frinavale
9,735 Recognized Expert Moderator Expert
Hi skysober,

I am by no means a PHP expert but I can explain why your image doesn't show up.

First of all, in order to display an image in your web page you have to use the HTML <img> tag. See w3c for more information about the HTML img tag.

When a webpage renders an image it needs to retrieve that image from the web server. That means that the image has to exist on the web server in order for the browser to retrieve it.

In your case there is no image on the web server for the web page to retrieve....you r image is stored in a database.

So, how do you get around this?
Well, instead of having the web page retrieve the image from a file on the web server, have it retrieve the image by calling a php script that retrieves the image from the database.

This php script does not return HTML like a normal php script would.
Instead this php script will retrieve the bytes that are the image from the database. Once the php script has retrieved the image it will send the bytes (that are the image) to the browser.

Since the script does not return HTML you have to change the Response Content-Type Header. That way when the image is sent to the browser, the browser will know that it is an image (and not HTML) so that it can render it properly.

With this in mind, take a look at the suggestion that Dormilich posted.
He suggested that you create a php file that reads the image from the database into memory...change the Content-Type to "image"...a nd send the image to the browser.

In order for your page to display the image you need to use an HTML <img> tag (Dormilich has posted code showing you how to use this).

The <img> tag has to call the php script that returns the image in order to display the image in the web page. You will have to provide the ID of the image as a parameter to the php script so that it can retrieve the right image......

In order words, take a look at what Dormilich has recommended ;)

-Frinny
Nov 30 '09 #4
skysober
9 New Member
The image is on the server. It is in the uploads folder. If I copy paste the result of $imagelocation into my browser, it shows the image just fine.

I have no clue as to what a somthing.php?so mething means. I only know html. basic PHP, an almost no SQL. This was my first attempt at reading a SQL, something that is probably quite easy for some, but is quite confusing to me.

I do know the images themselves are not stored in mysql, but actually stored in the upload folder and the mysql records that location. That confuses me a lot when someone says they are stored in the mysql.

Thanks!
Nov 30 '09 #5
Frinavale
9,735 Recognized Expert Moderator Expert
I'm not really sure that I understand your problem completely but one thing is for sure: the image is not stored in a database.

If your image is on the server, then it has to be in a directory that is accessible to web browsers.

Make sure that your image is moved to a directory that is in your website.
Once it is there your img tag will be able to download it.

For example, if you move your image to a folder called "images" that is within your website on your sever your img tag would look like:

Expand|Select|Wrap|Line Numbers
  1. <img src='www.mydomain.com/images/theImage.jpg' alt='the image' />
  2.  
In your case the URL to the image is stored in the $full_location variable...so you would have something like:

Expand|Select|Wrap|Line Numbers
  1. <img src='<?php echo $full_location; ?>' alt='the image' />
I have no idea how your database is even involved in this problem...???

-Frinny
Nov 30 '09 #6
skysober
9 New Member
Thanks, but this is turning away from the sql problem. HTML I know. I can make a link to a photo in a folder.

The mySQL simply stores the photos locations. When a member uploads a photo into uploads, the sql records this. I wish to read the sql, have it finds the name and location of the photos, and and then show the photos by that member.

My original code that I made at the beginning of this thread does all this, except actually showing the photos. Instead of the photos, it gives a text of "http://www.MySite.com/forum/uploads/NameOfThe1stPho to.jpg." , "http://www.MySite.com/forum/uploads/NameOfThe2ndtPh oto.jpg." , etc.
Nov 30 '09 #7
skysober
9 New Member
this is my present result when I run the peek.php

319 1
Image Date: 1235181668
Image Size: 88175
Image Width: 739
Image Height: 1000
location: monthly_02_2009/post-319-1235181668.jpg


full location: http://www.MySite/forum/uploads/mont...1235181668.jpg
Nov 30 '09 #8
Frinavale
9,735 Recognized Expert Moderator Expert
Your images are stored on the web server, in a folder in the website.
Your database stores URL information that can be used to display the images uploaded by the user.

You have SQL that retrieves the URLs for the photos.....

You know that you need an <img> tag to display an image....

Why can't you display the images??

-Frinny
Nov 30 '09 #9
skysober
9 New Member
Now that is the $64,000 question that I asked here in the first place ;)

As I just posted the result when I run peek.php, it does NOT show the photo.
Nov 30 '09 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

6
9272
by: Larry R Harrison Jr | last post by:
I have Access XP, and the following code which is supposed to assign a JPEG to an image control: Me.Image9.Picture = "F:\Pictures\CP775_SonyDSCP50\FingerRockNight_Resize.jpg" I get this error though: microsoft access dont' supoort the format of the file
3
1462
by: Robert Lochon | last post by:
Hi, I'm trying to transfer the photos from my Canon EOS 20D to a folder on my hard-drive with a C# program (but the language doesn't matter). But the cam folder doesn't appear in the directory browser within my application, although it appears in the Windows explorer. I deduce that it is not recognized by Windows as a removable drive. So, here's my question : How can I handle the cam folder (is it really a folder ?) from a program ?
2
2223
by: Ross | last post by:
Hi I have an application using asp.net that I am running on my PC. The web form has a text box where you can enter a name for a new Photo category then click on the button. The code is intended to create a new directory under Photos such as "Relatives".
4
2273
by: Dave G | last post by:
Firstly, apologies as this is not strictly an Access problem. I have a Access 2003 database containing records about people, and each person has 2 photos associated with the record. The photos are stored in a 'photos' folder. When a record is displayed, so are the photos. It all works fast and well. But I'm now getting close to 50,000 records and although it still works well I'm worried about having 100,000 jpgs in one folder.
2
1353
by: =?Utf-8?B?TGlhbQ==?= | last post by:
My Photos folder opens automatically on startup and re-opens instantly when I close it. Occasionally a small black banner appears and disappears with the words "My Photos" on it. My Photos keeps re-asserting itself as the live window, so for example I cannot even use Start, Shut Down to shut down my computer, as there is no time to click Shutdown Computer before My Photos goes active again. I have scanned for viruses using AdAware and...
10
2279
by: K. | last post by:
Hello all! I have a question to you. I would like to create photo gallery. I wonder if I should store photos (uploaded by users) in database $data = file_get_contents($_FILES); $data = mysql_real_escape_string($data);
1
1074
by: David C | last post by:
We have an intranet application that displays file folders assigned to that job. Each file folder has 5 subfolders under it and are listed in a TreeView. When we click on the folder it shows the file names in a DataGrid. It works perfect for 4 of the folders, but when we click on the folder named "Photos" (mostly jpg files) it prompts us for username and password. Any idea what might cause this? Thank you. David
1
3608
by: cumupkid | last post by:
II am trying to create a form that will allow me to upload photos to a folder in the site root directory and add the information to the mysql db at the same time. I have created two forms, one that uploads to photo to the folder in the site root diorectory. One that uploads the info to mysql database. but... When I try to upload them both ways at the same time i cant get it. I am Including code for both pages i have working. Code for...
6
3527
by: gubbachchi | last post by:
Hi, Which is the best data type to store photos in mysql. BLOB is same as varchar type and increases the search time. Apart from BLOB, is there any other data type to store photos.
0
9691
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9551
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10505
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10253
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7580
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5471
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5606
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4149
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2945
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.