Jump to content

file upload from another site


The Little Guy

Recommended Posts

I don't know If this is close, but this is wat I came up with. I get no errors, but it doesn't save the image to my server. I also don't know how fwrite would fit into this, since the file must exist to write to it.

 

$handle = fopen($url, "wb");
$contents = fread($handle, filesize($url));
if (!copy($contents, time().$url)) {
echo "failed to copy $file...\n";
}
fclose($handle);

You could also do something like this:

 

<?php
//I took your avatar as an example:

$url = "http://tzfiles.com/users/ryan/image.gif";
$extension = strrchr($url, ".");
while (!file_exists($name = rand(10,99).time().$extension)); //Create a unique file-name
$h = fopen($name, "w"); //Create the file
fwrite($h, file_get_contents($url));
fclose($h);
echo $name." Created!";

?>

 

Of course you should add some validation (that the url is ok and the file-type is ok etc') and some changes, but you get the idea.

 

 

Orio.

That didn't work

 

Is the $name variable ok? $url is defined from a form

 

foreach($img as $url){
$extension = strrchr($url, ".");
while (!file_exists($name = 'product/large/'.rand(10,99).time().$extension)); 
$h = fopen($name, "w"); //Create the file
fwrite($h, file_get_contents($url));
fclose($h);
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.