Archive for February 22, 2007

Force-download use PHP

Wuih..
There’s long time for me do not write any to here.
It’s cause my job deadline.. hehehe…

Anyway, Now, I want to write about force-download on PHP.
Why i write this? Yeah, i just feel that this technique was good for share private download file(s), cos many my friend ask me if they add file in public_html it is not secure, and not private.

So please do like this:

/home/project/public_html/ //<<< this path for world
/home/project/content/ //<<< this for private share file

And every file will download is from private and if want to download must login 1st, and script will like this.

<?php
define("DOWNLOAD_PATH","/home/project/content/"); // location to download
class loginToDownload{


var $username = "guntur"; //User can get from DB
var $password = "test"; //Password can get from DB
var $file_to_download = "test.txt";

function authen($user,$pass,$filename){
if($user == $this->username and $pass == $this->password ){
//Get file
$filephysics = DOWNLOAD_PATH.$filename;
if( $this->download($filephysics) ) return true; //success download
}


return false; //failed to download
}


function download($fname){
if(! file_exists($fname) ) return false; //Checkin' file
$filesize = filesize($fname);
$filemimetype = mime_content_type($fname);
$exten = end( explode($fname,".") );


header('Content-type: '. $filemimetype );
header('Content-Disposition: inline ; filename="doload.'. $exten . '" ');
print(file_get_contents($fname));
exit;
}
}//end class
?>

And please try, and report if wrong, cos i don’t test it :D
OK, bro, have nice try…

Leave a Comment

CakePHP vs Symfony, hmm..???

After i found a PHP framework who is called cakePHP, now i heard about the other ones framework which it’s name Symfony PHP5.

So what is different between both of its …? I don’t know much, but i can see several difference from its.

  • Installation, server requirement phpCake use PHP 4.3 or greater, and Symfony must use 5
  • Database, Symfony compatible with most engine like MySQL, Ms SQL, PostgreSQL and Oracle, but i don’t see cakePHP can use Oracle engine.
  • Models, Symfony has two versions of the data object model in two different directories and not for cakePHP
  • Propel XML, Symfony understands the Propel native XML schema format and i don’t think so on cakePHP

There is a several which i think difference from both, and i need your suggestion, input or addition to complete this article. And please correct if on above is wrong.

Comments (2)