I have made this script for uploading remote files but the file is not uploaded to server and the database for var1 remains empty. Here is my code.
HTML:
<form enctype="multipart/form-data" id="form1" method="post" action="">
<p><label>Upload songs</label>
<input type="text" name="song"><input type="submit" value="Submit" class="button"></p>
</form>
PHP:
$uri = copy1_file($_POST['song']);
$story['v1'] = $uri;
$url = $_POST['song'];
$file = fopen ($url, "rb");
if ($file) {
$newf = fopen ($uri, "wb");
if ($newf) {
while(!feof($file)) {
fwrite($newf, fread($file, 1024 * 8 ), 1024 * 8 );
}
}
}
if ($file) {
fclose($file);
}
if ($newf) {
fclose($newf);
}
else {
return false;
}
}
I have checked the error log but nothing is coming. Where I am doing a mistake?
Read up on PHP File Uploads.
Try this to debug your script:
Do you see anything?
EDIT: Okay, I see you more clearly defined “remote files.” You have to use a “text” input to receive the URL. How did you get around the standard file selection dialog?
It looks like your code will work as-is if you just change the
<input/>type to “text”.EDIT 2: I noticed you updated your post to have
<input type="text"/>so you already have a URL making it through to your script. Check to see if your host has allow_url_fopen enabled. If not, your URL will not be retrieved byfopen(). You will have to usecURLinstead.EDIT 3: Could it be that your
copy1_filefunction never actually returns the uri? There are a lot of errors in the code in that function. Ex:copy1_fileis receiving a url, why does it have$file['name']at the top? And later reference$_POSTdirectly? There are more errors. Check it closely and correct them, then it should work fine since you sayfopen(url)is known to work with your host.