MySQL Forums
Forum List  »  PHP

INSERT file path/URL into table
Posted by: Simon Rodgers
Date: July 25, 2011 09:58AM

Hi there. Here's the scenario:

I have a couple folders on images stored in Amazon AWS cloud storage. I can access each image with a URL. I want to store the URL for each image in a mySQL DB, which is also located in the cloud, at Amazon.

I have found many PHP scripts for inserting the image URL into the DB, but I am creating the DB using MySQL Query Browser, not PHP. So my question is, what is the MySQL correct syntax to insert a URL into a table. I have been using this:

INSERT INTO image_test
VALUES (NULL, "https://s3.amazonaws.com/myimagefolder/image1.JPG";);

The datatype for the URL is VARCHAR.

This seems to be working, but I am having trouble retrieving the image. To retrieve I am using a PHP script as follows:

header('Content-type: image/JPG');

//connection vars

mysql_connect($dbhost, $dbuser, $dbpass) or die("Can not connect to database: ".mysql_error());

mysql_select_db($dbname) or die("Can not select the database: ".mysql_error());  

$query = mysql_query("SELECT * FROM image_test WHERE pid=2");
$row = mysql_fetch_array($query);
$content = $row['image_url'];


fopen($content, "r");

I have also tried varies other ways of opening the URL, such as:

echo "<img src='$row['image_url']';>"

and..

<img src="<?php echo $row['image_url'] ?>">

and..

readfile($content);

None of which have worked. I am not sure if the issue is with uploading the URL, or retrieving it, so I want to post on here, to ensure I am starting out correctly with the URL insert.

Any hints, tips, or a good tutorial would be appreciated, thanks.



EDIT-- I have been doing some more testing, and found the the issue seems to be, the insert method I am using is not putting the full URL in the DB. I inserted a few rows, then queried what was there, and here are the results:

pid image_url
2 https://s3.amazonaws.com/image_folder
3 https://s3.amazonaws.com/image_folder


As you can see, the image names are missing. What could be causing this?



Edited 1 time(s). Last edit at 07/25/2011 10:16AM by Simon Rodgers.

Options: ReplyQuote


Subject
Written By
Posted
INSERT file path/URL into table
July 25, 2011 09:58AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.