Save picture from website to a server

I’m trying to save a picture to my server, from a different website. Normally I would first download the picture from a website to my computer, and then upload the picture from my computer to my server. I want to skip my computer and download the picture straight from a website to my server.

Here’s what I managed to code, but it’s not working:


<?
$path = "http://i.a.cnn.net/cnn/.element/img/1.5/ceiling/logo_cnn.gif";
$image = file_get_contents($path);

move_uploaded_file($image,"upload/uploadedfile");

?>

Look at [fphp]copy()[/fphp] :).

I’ve modified my code to:

<?
 $path = "http://i.a.cnn.net/cnn/.element/img/1.5/ceiling/logo_cnn.gif";
 $image = file_get_contents($path);
 
 $newfile = "cnn.gif";
 
 if (!copy($image, $newfile)) {
    echo "failed to copy $file...\
";
 }
 ?>
 

but I get this error message:

Warning: copy(GIF89aÎ): failed to open stream: No such file or directory in /home/adam/public_html/test/image.php on line 7
failed to copy …

What’s wrong?

hi
i hope this will help you:

<?php

   if ($_SERVER['REQUEST_METHOD'] == "POST" )
    {

	// grab  the url
	$url = $_POST['theFile'];

	print $url."<br/>";

	// return ifo about the url
	$path_parts = pathinfo($url);

	echo $path_parts['dirname'], "\
" ."<br>";
	echo $path_parts['basename'], "\
" ."<br>";

	// save the file name in variable
	$image = ($path_parts['basename']);

	echo $path_parts['extension'], "\
";

		// copy the file to you folder
		copy($url,"fred/" .$image);

	}


?>


<form action="test5.php" method="post" enctype="multipart/form-data">
  Send thus file:<br>
  <input name="theFile" type="text"><br>

  <input type="submit" value="Send file">
</form>

thanks

Works like a charm. Thank you :slight_smile:

This really isn’t any of my business, but how come your username for your hosting environment is “horny” lol.

:rofl: