Remote File Copy

I’m trying to create a script to copy a remote file to my host. Whenever I run it, I get an error like this:


Warning: copy(/2.gif) [function.copy]: failed to open stream: Permission denied in /var/www/web1/html/upload.php on line 22
2.gif has been uploaded to /


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>upload file</title>
</head>

<body>
<?php 

	// only upload if user filled out entire form
	if($_POST['url'] && $_POST['password'] && $_POST['directory'])
	{
		if($_POST['password'] != 'password')
			die('wrong password');
		
		// extract file name from full URL
		$fileName = str_replace('http://', '', $_POST['url']);
		$fileName = strchr($fileName, '/');
		$fileName = str_replace('/', '', $fileName);	
			
		copy($_POST['url'], $_POST['directory'] . $fileName);	
		
		printf('<b>%s</b> has been uploaded to <b>%s</b>', $fileName, $_POST['directory']);
	}
	else 
	{
?>
	<form method="post" action="upload.php">
		URL of file you want to download:
		<br />
		<input name="url" type="text" size="100" maxlength="300" />
		<br/>
		<br/>
		To this directory:
		<br />
		<input name="directory" type="text" size="100" maxlength="100" value="/" />
		<br/>
		<br/>
		Password:
		<br/>
		<input name="password" type="password" size="10" maxlength="10" />
		<br />
		<br />
		<input type="submit" value="upload" />
	</form>

<?php
	}
?>
</body>
</html>