Page 1 of 1
Download swf file to server via php script
Posted: Mon Feb 28, 2011 8:48 pm
by davidius
I am looking for a way to download SWF files onto my server via a php form script. I input the URL into a text box, click submit, and it automatically downloads to a specified directory.
Can anyone lead me into the correct direction?
Thanks : )
Re: Download swf file to server via php script
Posted: Tue Mar 01, 2011 1:08 am
by cpetercarter
Something like this (taken from a podcasting cms which I have written):
Code: Select all
$sourcefile = fopen ($_POST['linkurl'], "rb")
OR die("I could not find a url");
$destfile = fopen ($newfilepath, "wb");
$eof = false;
$filesize = 0;
//copies the file in fragments of 1024 bytes
do {
$file = fread ($sourcefile, 1024) OR $eof = true;
$filesize = $filesize + 1024;
fwrite ($destfile, $file) OR fclose($destfile);
} while ($eof==false);
fclose($sourcefile);
$_POST['linkurl'] is the url which you posted from your form. $newfilepath is the path from the server root to the place where you want to store the file (eg /www/mysite/public_html/swf_files/myfilename.swf). If anyone would like to suggest improvements, I would be very interested.
Re: Download swf file to server via php script
Posted: Tue Mar 01, 2011 12:16 pm
by John Cartwright
file_get_contents()?