Two Plus Two Publishing LLC Two Plus Two Publishing LLC
 

Go Back   Two Plus Two Poker Forums > Other Topics > Programming

Notices

Programming Discussions about computer programming

Reply
 
Thread Tools Display Modes
Old 07-10-2012, 05:54 PM   #1
centurion
 
OutHouse's Avatar
 
Join Date: May 2008
Location: Tieing!
Posts: 196
<-- PHP r'tard

I am a non programmer trying to program so I need help.

I have a long list of image URLs and I simply need to write something that will grab them and put them all into a folder. I'm about ready to break something valuable so I decided to see if someone wouldn't mind helping.

So far, I have a directory that contains a .txt of all the URLs (one per line), a folder where I want the images stored, and this php script that I'm not smart enough to make work which is so far:

<?php
$filename = "urls.txt";
$handle = fopen($filename, "r");
$contents = fgets($handle [, int $length ]);
$image = file_get_contents($contents);

//I'm pretty sure nothing below here is sensical

$savefile = fopen('images/image.jpg', 'w');
fwrite($savefile,);
fclose($savefile);
?>

Most of this is from reading tutorials, familiarizing myself as much as possible with info from php.net, and pasting code... so I admit to being a noob poser who should just hire someone to do this type of thing. I'd really like to get this working.
OutHouse is offline   Reply With Quote
Old 07-10-2012, 06:18 PM   #2
bacon wannabe
 
Freakin's Avatar
 
Join Date: Sep 2004
Posts: 16,998
Re: <-- PHP r'tard

Why php? Is this for your own purposes?
How about powershell?
Code:
$client = new-object System.Net.WebClient
$urlList = Get-Content c:\urls.txt
    foreach($url in $urlList)
    {
		if ($url -match '([\w\d_-]*)\.?[^\\\/]*$')
		{
	        $client.DownloadFile($url, "c:\" + $Matches[0])
		}	
    }
gets list of urls from c:\urls.txt
saves files to c:\whateverfilenameisfromurl
Freakin is offline   Reply With Quote
Old 07-10-2012, 06:33 PM   #3
centurion
 
OutHouse's Avatar
 
Join Date: May 2008
Location: Tieing!
Posts: 196
Re: <-- PHP r'tard

I appreciate that example. PHP because it's the only language I have any remote familiarity with. I wouldn't even know where to start with another structure.
OutHouse is offline   Reply With Quote
Old 07-10-2012, 08:02 PM   #4
Pooh-Bah
 
jmark's Avatar
 
Join Date: Dec 2003
Location: US
Posts: 3,609
Re: <-- PHP r'tard

Can you get access to linux / cygwin?

wget -i urls.txt
jmark is offline   Reply With Quote
Old 07-10-2012, 08:48 PM   #5
bacon wannabe
 
Freakin's Avatar
 
Join Date: Sep 2004
Posts: 16,998
Re: <-- PHP r'tard

lol yeah batch + wget (assuming windows) was going to be my next suggestion. this is a simple script that you are overcomplicating (moreso than my powershell overcomplicating ).
Freakin is offline   Reply With Quote
Old 07-10-2012, 10:27 PM   #6
gwp
grinder
 
gwp's Avatar
 
Join Date: Jan 2006
Location: Achieving illumination...
Posts: 412
Re: <-- PHP r'tard

look at the following:

imagecreatefromstring()
imagejpeg()
gwp is offline   Reply With Quote
Old 07-11-2012, 12:22 AM   #7
adept
 
txpstwx's Avatar
 
Join Date: Jun 2008
Posts: 1,125
Re: <-- PHP r'tard

Code:
<?php
$filename = "urls.txt";
$urls = file($filename, FILE_IGNORE_NEW_LINES);
foreach ($urls as $url) {
    $url_parts = pathinfo($url);
    $img = 'images/' . $url_parts['basename'];
    copy($url, $img);
}
?>
Requires allow_url_fopen to be set to on.
txpstwx is offline   Reply With Quote
Old 07-11-2012, 03:53 PM   #8
veteran
 
MikeyObviously's Avatar
 
Join Date: Jan 2004
Location: hella swagged out
Posts: 3,160
Re: <-- PHP r'tard

Yeah this is something the command line utility Wget can handle:
http://www.gnu.org/software/wget/

It has been mentioned, but wanted to spell it out more...

edit: There is a windows version, I had to use it at work a few years back.
MikeyObviously is offline   Reply With Quote
Old 07-27-2012, 02:01 AM   #9
adept
 
Join Date: Mar 2006
Location: San Diego
Posts: 1,103
Re: <-- PHP r'tard

Since you're looking to do this in PHP I'll tell you how I would go about it if I had to use PHP but I won't give you the code to do it.

First I would iterate over every line in that text file
Then I would grab the URL and send a GET request to the URL using cURL (I recommend cURL if you're using PHP but you can use any HTTP library you like)
Have cURL return the file
Save said file to the directory of your choice

Here's documentation on PHP's implementation of cURL: http://php.net/manual/en/book.curl.php
RICHI8 is offline   Reply With Quote
Old 08-02-2012, 09:51 AM   #10
stranger
 
shift+'s Avatar
 
Join Date: Jul 2012
Posts: 2
Re: <-- PHP r'tard

Code:
<?

$urls = explode(PHP_EOL, file_get_contents("urls.txt"));

foreach($urls as $url)
file_put_contents("images/".basename($url), file_get_contents($url));

?>
shift+ is offline   Reply With Quote

Reply
      

Thread Tools
Display Modes

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



All times are GMT -4. The time now is 09:18 AM.


Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.6.0 ©2011, Crawlability, Inc.
Copyright © 2008-2010, Two Plus Two Interactive