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 : )
Download swf file to server via php script
Moderator: General Moderators
-
cpetercarter
- Forum Contributor
- Posts: 474
- Joined: Sat Jul 25, 2009 2:00 am
Re: Download swf file to server via php script
Something like this (taken from a podcasting cms which I have written):
$_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.
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);- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: Download swf file to server via php script
file_get_contents()?