Jump to content

Copying Remote Files With


hellonoko

Recommended Posts

I have the below simple code that I use to copy remote files.

 

It allows me to copy a file even if its larger than expected or with slower connection as I am copying mp3 and sometimes they are 100megs sometimes 4megs.

 

However when I came across this link:

this.bigstereo.net/wp-content/uploads/2009/04/stomp-yo-shoes-bloody-beetroots-remix-the-aston-shuffle-vocal-edit-1.mp3

 

My script basically hangs although the link is not broken and downloads perfectly.

 

What I have noticed is that the other links load in my browser with quicktime and this link load as a Save As... dialog.

 

Any ideas?

Is there a better method I can be using to remotely copy files while still not worrying about the max_execution_time and max_file_size?

 

Thanks.

 

function copyFile($url,$dirname)
{

$url = str_replace(' ', '%20', $url);
//$url = urlencode($url);

@$file = fopen ($url, "rb");
if (!$file) 
{
	echo "Failed to copy $url !";

	return false;
}
else 
{	
	//copy file
	$filename = basename($url);
	$fc = fopen($dirname."$filename", "wb");
	while (!feof ($file)) 
	{
		$line = fread ($file, 1028);
		fwrite($fc,$line);
	}

	fclose($fc);
	//echo "File $url saved to PC!";

	$time_end = microtime(true);
	$time = $time_end - $time_start;

	if ( $time > 60 )
	{
		$time = $time / 60;
		echo "File: $filename coppied in $time minutes";
	}
	else
	{
		echo "File: $filename coppied in $time seconds";
	}

	return true;
}
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.