Download swf file to server via php script

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
davidius
Forum Newbie
Posts: 1
Joined: Mon Feb 28, 2011 8:45 pm

Download swf file to server via php script

Post 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 : )
cpetercarter
Forum Contributor
Posts: 474
Joined: Sat Jul 25, 2009 2:00 am

Re: Download swf file to server via php script

Post 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.
User avatar
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

Post by John Cartwright »

file_get_contents()?
Post Reply