Skip to content
WJunction - Webmaster Forum

Image Remote Upload Script

Status
Not open for further replies.
I'm having trouble making a script that will grab multiple images from urls then save it to the current directory where the script is located :( I don't need any design, just a script that will be able to do this. Here's what i'm expecting it to look like <3

[SLIDE]http://lulzimg.com/i14/289633.jpg[/SLIDE]

Anyone knows how?

​
 

11 comments

So you're going to input a set of image urls into the first text box, and when run the image will grab those images and save them to a specified directory, yes? What does the output box do? Echo the links of those images relative to the url specified in the script?

Also, is this going to be a private script? If yes, you can be a little relaxed in terms of security.

Post your current code here.
 
ever heard about curl, Just chk Google for tuts. Curl can leech the image for u on ur server ;)
 
dump curl, go for an easier solution if it's going to be private - file_get_contents and file_put_contents
 
okay telling it real quick!

get the urls from the textarea via POST. Explode them in an array.

then implement this logic..

Code:
foreach($arr as $url){
    $img = file_get_contents($url);
    file_put_contents("/path/to/file", $img);
}

not tested but should do the job.. :)
 
Oh no, what am i going to do with those php codes? my nose is bleeding.. :( I do not know what i'll do LoL XD
 
Last edited:
This, is technically supposed to work:

PHP:
<?php

$imgPath = "/home/admin/domains/xyz.com/folder/"; //path where images are to be located
$baseurl = "http://xyz.com/folder/images/"; //the base path for images as a url (refer below)
//so if your images are supposed to be at http://domain.com/img/xyz.jpg then your baseurl is 'http://domain.com/img/' (with trailing slash)
//essentially, both the above paths should have something in similar with regards to folder structure

echo '<form enctype="multipart/form-data" action="" method="POST">';
echo '<textarea rows="10" cols="50" name="urls"></textarea>';
echo '<input type="submit" name="submit" value="submit" />';
echo '</form>';

if (isset($_REQUEST['submit']))
{
	$urls = explode("\n", $_POST['urls']);
	$imgarray = array();
	foreach ($urls as $url)
	{
		$url = trim($url);
		$imgname = basename($url);
		$localimg = $imgPath . $imgname;
		$img = file_get_contents($url);
		file_put_contents($localimg, $img);
		$url = $baseurl . $imgname;
		$echo "$img <br />";
	}
}

?>

Remember to change the paths on the top :)
 
Last edited:
Thank You! Works Great! Just Awesome.. :wub:

edit: everything was going fine, but when i go to check the file, it says 404 not found because the new file now ends from sdfsd.jpg(original file) to sdfsd.jpg%20%0d. What's wrong?
 
Last edited:
Just remember I'm not sanitizing filenames or checking for extensions or anything of that sort in the script, since you said it'd be for private use. So you're best off randomly naming it to prevent someone being able to type it in. It's not very secure, but it'll get the job done.
 
Just looked at my code and I must of been drunk or something when I posted it. I created an unnecessary array and a foreach statement. Edited it a little more.
 
Status
Not open for further replies.

About the author

H
Senior Member · Joined
I am Hillsid3. I consider myself as extraordinary - and we are unique in our own ways. listening to music, watching...
1,535
Messages
13
Reactions
38
Points
Grow your business

Advertise on WJunction

Connect with an established international community of webmasters, hosting providers, developers and online entrepreneurs.

  • Premium & Premium+ Sticky
  • Dedicated section banners
  • Site-wide banner advertising
Explore advertising options
Back
Top Bottom