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. - <?
-
$username="MyUserName";
-
$password="MyPassWord";
-
$database="MyDataBase";
-
$x=date("j");
-
-
mysql_connect(localhost,$username,$password);
-
@mysql_select_db($database) or die( "Unable to select database");
-
$query="SELECT * FROM ibf_attachments";
-
$result=mysql_query($query);
-
-
$num=mysql_numrows($result);
-
-
mysql_close();
-
-
echo "<b><center>Database Output</center></b><br><br>";
-
-
$i=0;
-
while ($i < $num) {
-
-
$member=mysql_result($result,$i,"attach_member_id");
-
$isimage=mysql_result($result,$i,"attach_is_image");
-
$imagedate=mysql_result($result,$i,"attach_date");
-
$imagesize=mysql_result($result,$i,"attach_filesize");
-
$imagewidth=mysql_result($result,$i,"attach_img_width");
-
$imageheight=mysql_result($result,$i,"attach_img_height");
-
$imagelocation=mysql_result($result,$i,"attach_location");
-
-
// this sets the image location to a full path
-
$full_location = "http://www.MySite.com/forum/uploads/$imagelocation";
-
-
-
-
echo "<b>$member $isimage</b><br>
-
Image Date: $imagedate<br>
-
Image Size: $imagesize<br>
-
Image Width: $imagewidth<br>
-
Image Height: $imageheight<br>
-
location: $imagelocation <br>
-
<br><br>
-
-
// this actually shows the link, but not clickable, nor will it display image here.
-
// I can copy and paste it in browser and it is correct path.
-
full location: $full_location<br>
-
-
<hr><br>";
-
-
?>
-
-
<?PHP
-
-
$i++;
-
}
-
-
?>
any help would be apprecitated!
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. - // in HTML (image from DB)
-
<img src="image.php?id= xyz" width="…" height="…" alt="…">
- // image.php
-
header("Content-Type: image/jpeg"); // or whatever image type you have
-
// connect to DB
-
// query DB for image (using $_GET)
-
// return data:
-
echo $image;
-
// 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 …
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.
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
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!
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: -
<img src='www.mydomain.com/images/theImage.jpg' alt='the image' />
-
In your case the URL to the image is stored in the $full_location variable...so you would have something like: - <img src='<?php echo $full_location; ?>' alt='the image' />
I have no idea how your database is even involved in this problem...???
-Frinny
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.
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
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.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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
|
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 ?
|
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".
|
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.
|
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...
| |
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);
|
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
|
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...
|
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.
|
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...
|
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,...
| |
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...
|
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,...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
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...
| |