Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Remote image DB import
Old 02-25-2009, 05:31 PM Remote image DB import
Junior Talker

Posts: 3
Name: Ian
Trades: 0
I have a site where all the images are currently in a directory on another server (I did it at the time to conserve bandwidth), and am now looking to write a script that will import them from there directly into a database on a dedicated server as I'm getting rid of the other. I'm looking to write a script to load them from that server via the URL, and then insert it into my MYSQL database as a longblob file? I'm just trying to find an efficient way to make the move, and thought that this would be the best way to handle it.

Here's what I have:
Code:
<?php
 
$photo = "http://www.example.com/images/picture.jpg";
$image = file_get_contents($photo, FILE_BINARY);
 
$dbname = "database";
 
$connection = @mysql_connect("localhost", "user", "pass") or die("Couldn't Connect.");
 
$db = @mysql_select_db($dbname, $connection) or die("Couldn't Select Database.");
 
$table = "images";
 
$query = sprintf("INSERT INTO $table ('image') VALUES ('%s')",
mysql_real_escape_string($image, $connection));
 
mysql_query($query, $connection);    
?>
I can't get it to load the image, and then insert it into the LONGBLOB cell. I can't find another example of this online or anything similar, and the file_get_contents reference on php.net obviously doesn't explain this. So thank you for your help so far, and I'm sure this is probably easier than I'm making it out to be. The problem is that there is a row being inserted, but the blob has 0 Bytes. So is the above the correct function to load the image before it's inserted, or is the problem that I'm using the wrong syntax for this function?

Thank you in advance for your assistance. - Ian
patsfans is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 02-27-2009, 06:34 AM Re: Remote image DB import
Super Spam Talker

Latest Blog Post:
PSD Squirrel Launched
Posts: 932
Trades: 7
Hi Ian,

Why don't you debug what you have by outputting the image binary just so you know you have it? Output it before it inserts it.. just once.. so you know its there?

If its not, then you know the problem is with the file copy rather than the mysql insert.

Get back to me on that and we can see where to look next ..

Cheers,
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
Sir P is offline
Reply With Quote
View Public Profile Visit Sir P's homepage!
 
Old 02-27-2009, 12:34 PM Re: Remote image DB import
Junior Talker

Posts: 3
Name: Ian
Trades: 0
Quote:
Originally Posted by Sir P View Post
Hi Ian,

Why don't you debug what you have by outputting the image binary just so you know you have it? Output it before it inserts it.. just once.. so you know its there?

If its not, then you know the problem is with the file copy rather than the mysql insert.

Get back to me on that and we can see where to look next ..

Cheers,
Thank you so much for your assistance. I took your advice, it appears I've figured it out (at least the problem anyway). If the URL is not pointing to a file on the local server, it won't load the image (it loaded it via a URL that was to a file on the same domain). Is there a different command I need to use, or a function in .htaccess to tell the server to allow the loading of remote files?
patsfans is offline
Reply With Quote
View Public Profile
 
Old 02-27-2009, 02:54 PM Re: Remote image DB import
Junior Talker

Posts: 3
Name: Ian
Trades: 0
Thanks to you I contacted a friend at the server company and come to find out it was a firewall issue. The added the domain to the firewall white list and it worked perfectly.

Thank you for taking the time to try and help, I appreciate it. And I hope you have a good weekend! - Ian
patsfans is offline
Reply With Quote
View Public Profile
 
Old 02-27-2009, 04:26 PM Re: Remote image DB import
Super Spam Talker

Latest Blog Post:
PSD Squirrel Launched
Posts: 932
Trades: 7
great work
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
Sir P is offline
Reply With Quote
View Public Profile Visit Sir P's homepage!
 
Reply     « Reply to Remote image DB import
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.25783 seconds with 12 queries