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!
Your problem has very little to do SQL.
In fact it sounds like you're connecting to the database and retrieving the data correctly!
Your MySQL Database simply holds the URLs to the images that you want to display.
MySQL is a database of information...it's not supposed to "Display" anything at all. It just holds information. It is the browser's job to display things...and the only way the browser is going to know How you want to display something is if you use HTML to describe how you want things to be displayed.
So, when you retrieve the data from the SQL database you need to create/generate HTML to tell the web browser how to display the data. This means that if you want the web browser display an image, you have to use the HTML <img> tag to display the image.
Did you try: -
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>
-
Image: <img src='$full_location' alt='the image' /> <br>
-
<br><br>";
???
-Frinny
22 3866
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.
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....your 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"...and 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?something 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!
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/NameOfThe1stPhoto.jpg." , "http://www.MySite.com/forum/uploads/NameOfThe2ndtPhoto.jpg." , etc.
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.
Oh wait a second, you don't want to display the image (maybe??)...you just want to create a hyperlink to the image???
A hyperlink (a "link") is created using the HTML <a> tag (an anchor).
In this case you would use the <a> tag instead of the <img> tag and use the href property instead of the src property....
Do you have a public link to this website?
-Frinny
I have a feeling that you aren't creating the URL to the image properly.
Have you researched the $_Server variable?
$_SERVER[’PHP_SELF’], $_SERVER['REQUEST_URI'], and $_SERVER[’SCRIPT_NAME’] all return information about the php script that was requested. Maybe you could use one of these to find the URL to the images?
Like I said I'm not a PHP expert, so I'm not entirely sure what the best way to get the URI of your website.....
One other thing, are you Sure that the uploads folder is accessible?
-Frinny
the resulting url is perfect. I can copy paste it into a new browser page and it works 100% showing the photo.
thanks. I give up on this. reading SQL is not going to show the photo no matter what I try. I have spent about 25 hours fighting this. I'm sure an sql xpert does this on a daily basis and is a joke for him, but I can't figure it out.
Thanks for trying!
Your problem has very little to do SQL.
In fact it sounds like you're connecting to the database and retrieving the data correctly!
Your MySQL Database simply holds the URLs to the images that you want to display.
MySQL is a database of information...it's not supposed to "Display" anything at all. It just holds information. It is the browser's job to display things...and the only way the browser is going to know How you want to display something is if you use HTML to describe how you want things to be displayed.
So, when you retrieve the data from the SQL database you need to create/generate HTML to tell the web browser how to display the data. This means that if you want the web browser display an image, you have to use the HTML <img> tag to display the image.
Did you try: -
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>
-
Image: <img src='$full_location' alt='the image' /> <br>
-
<br><br>";
???
-Frinny
I'm having a hard time following this thread (be it through no fault of your own, I'm just slightly sleepy with some wine in my blood).
Let us reiterate the exact problem; I don't want to know about anything that isn't specifically related to this problem - that only clouds my vision.
So, try this: *what* are you trying to do? What have you tried? What *isn't* working? What *is* working? What *errors* do you get?
No need to give up :)
Mark.
Edit: unless Frin's latest post clears the situation up.
wtf! You code works! I dunno what u did dif than I did with the src, but yours shows the photo! Now I can actually start to work with it where I can choose it to only show a member specific photos.
THANK YOU SO MUCH!!!!!
Hah :)
I'm glad you solved your problem.
Happy coding!
-Frinny
Thanks again! I can honestly say I think SQL is a neccesary EVIL ;)
hehe...
THANKS for the help!!!
I can honestly say I think SQL is a neccesary EVIL
I wouldn’t go as far as that… after all, it’s logical
@skysober
You'd be in a hell of a worse situation if you didn't have SQL (or any other query language). Flat file database? Ick!
Yeah Mark, if there was no SQL, i will be killing myself :)
Regards
Dheeraj Joshi
I can honestly say I think SQL is a neccesary EVIL
SQL is not evil once you understand it and how databases work.
It's funny but I do the same thing: I blame the thing I know the least about for the problems I'm experiencing. Sometimes it takes a while to see that it's something that I know that's causing the problem.
-Frinny
@Frinavale
It's always much easier and more satisfying to blame anyone and anything other than yourself ^_^
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...
|
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...
|
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...
|
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...
|
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...
|
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 =...
|
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...
|
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...
|
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: Kemmylinns12 |
last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
|
by: Naresh1 |
last post by:
What is WebLogic Admin Training?
WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
|
by: antdb |
last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine
In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
|
by: Matthew3360 |
last post by:
Hi,
I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
|
by: Carina712 |
last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
|
by: Rahul1995seven |
last post by:
Introduction:
In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
|
by: Johno34 |
last post by:
I have this click event on my form. It speaks to a Datasheet Subform
Private Sub Command260_Click()
Dim r As DAO.Recordset
Set r = Form_frmABCD.Form.RecordsetClone
r.MoveFirst
Do
If...
|
by: jack2019x |
last post by:
hello, Is there code or static lib for hook swapchain present?
I wanna hook dxgi swapchain present for dx11 and dx9.
|
by: DizelArs |
last post by:
Hi all)
Faced with a problem, element.click() event doesn't work in Safari browser.
Tried various tricks like emulating touch event through a function:
let clickEvent = new Event('click', {...
| |