Welcome to WebmasterWorld Guest from 54.162.248.199

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Images and PHP

Just a quickie regarding what is possible

     
5:19 pm on Jun 3, 2003 (gmt 0)

WebmasterWorld Senior Member nick_w is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Hi all,

I've done a bit of image uploading before and although it's not easy, it's not really hard either right?

Has anyone done this though: Set it up so that you could copy the image url (from another server) and have the script download the image and treat it like it was uploaded?

With me? - I'm building affiliate db's and need to automate the process of uploading product photos as much as possible.

Many thanks, hope it's understandable!

Nick

7:36 pm on Jun 3, 2003 (gmt 0)

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Since no one seems to have any grand insight the first things that come to mind are curl, GD or a socket. Haven't done anything like that really though.

I just get them to upload from their hard drive.

7:37 pm on Jun 3, 2003 (gmt 0)

WebmasterWorld Senior Member nick_w is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Yes, I may just try it out to see if it'll work with a 'browse' button on a form.....

thanks jatar...

Nick

7:39 pm on Jun 3, 2003 (gmt 0)

WebmasterWorld Senior Member nick_w is a WebmasterWorld Top Contributor of All Time 10+ Year Member



actually, saying that, there are lots of file functions that open urls etc, why would an image be any different?

If I could open the image and save it to a var then........ I'll have to think about this ;)

Nick

7:42 pm on Jun 3, 2003 (gmt 0)

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member



which is why I thought of curl. If you want to open a remote opage somewhere that is how to do it. Then when saving it you may need to use GD to test the type and then save/create a new image.
7:45 pm on Jun 3, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



just my $0.02

curl and such are quite slow

7:46 pm on Jun 3, 2003 (gmt 0)

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member



what would you suggest then Gibble?
7:47 pm on Jun 3, 2003 (gmt 0)

WebmasterWorld Senior Member nick_w is a WebmasterWorld Top Contributor of All Time 10+ Year Member



I don't have root. Curls an add on right?

Nick

7:58 pm on Jun 3, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yea, cURL [curl.haxx.se] is a command line program. Easiest way to run it from PHP is using one of the backtick-type commands.

% curl h-ttp://server.tld/image.gif > image.gif
8:04 pm on Jun 3, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you want to use cURL with PHP
www.phpfreaks.com/tutorials/49/1.php

I don't know what to recommend, I just know it's not fast :(

I suppose you could use wget from the command line...

[edited by: jatar_k at 8:12 pm (utc) on June 3, 2003]
[edit reason] delinked [/edit]

8:10 pm on Jun 3, 2003 (gmt 0)

WebmasterWorld Senior Member nick_w is a WebmasterWorld Top Contributor of All Time 10+ Year Member



I can execute command line apps from PHP?

Nick

8:43 pm on Jun 3, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



yes, there's a few different ways to execute a shell program via PHP. Take a look at the 'passthru' function which I *think* would be the most appropriate for what you're trying to do. All of the methods are listed here [us3.php.net]
8:54 pm on Jun 3, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you want to do command line, you could also to wget:

wget <url>
will get the file at the specified url and dump it into your current directory. to specify a directory and name, use
wget --output-document=<filename> <url>

You can also use --limit-rate=20kb for example to limit the max download rate at 20kb if you dont want to paralyze your server or the remote server. There are also options for specifying lists of files and such, just use the man page.

Also, php can directly download files on it's own and also write them:
[us3.php.net...]
fopen works the same on remote urls as local files if you are reading. Works for images just fine. Now the trick then becomes finding all the image urls.

11:25 pm on Jun 3, 2003 (gmt 0)

10+ Year Member



Wouldn't it be the most straightforward way to use a php function to read the contents of a URL (i.e. the picture file) into a variable? There is file_get_contents() as of PHP 4.3 (see php docs). I haven't used it yet but it sounds like the one that you want.
3:14 am on Jun 4, 2003 (gmt 0)

WebmasterWorld Senior Member drdoc is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Why not just use GD? [us2.php.net...]

imagecreatefromgd2 -- Create a new image from GD2 file or URL
imagecreatefromgd2part -- Create a new image from a given part of GD2 file or URL
imagecreatefromgd -- Create a new image from GD file or URL
imagecreatefromgif -- Create a new image from file or URL
imagecreatefromjpeg -- Create a new image from file or URL
imagecreatefrompng -- Create a new image from file or URL
imagecreatefromstring -- Create a new image from the image stream in the string
imagecreatefromwbmp -- Create a new image from file or URL
imagecreatefromxbm -- Create a new image from file or URL
imagecreatefromxpm -- Create a new image from file or URL
 

Featured Threads

Hot Threads This Week

Hot Threads This Month