Download File PHP Function
function download($path) {
//global $_SERVER['HTTP_USER_AGENT'];
$file=basename($path);
$size = filesize($path);
header("Content-Type: application/octet-stream");
header("Content-Type: application/force-download");
header("Content-Length: $size");
// IE5.5 just downloads index.php if we don't do this
if(preg_match("/MSIE 5.5/", $_SERVER['HTTP_USER_AGENT'])) {
header("Content-Disposition: filename=$file");
} else {
header("Content-Disposition: attachment; filename=$file");
}
header('Cache-Control: maxage=3600'); //Adjust maxage appropriately
header('Pragma: public');
header("Content-Transfer-Encoding: binary");
$fh = fopen($path, "r");
fpassthru($fh);
}
Tips and helps for my fellow PHP programmers.Here we are bound to build a PHP world.Anyone is welcome to share thier knowledge in PHP with others.Lets share and grow together
Showing posts with label file. Show all posts
Showing posts with label file. Show all posts
Tuesday, July 20, 2010
Remote File Size PHP Function
PHP function for finding remote file size
function remotefilesize($url, $user = "", $pw = "")
{
ob_start();
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_NOBODY, 1);
if(!empty($user) && !empty($pw))
{
$headers = array('Authorization: Basic ' . base64_encode("$user:$pw"));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
}
$ok = curl_exec($ch);
curl_close($ch);
$head = ob_get_contents();
ob_end_clean();
$regex = '/Content-Length:\s([0-9].+?)\s/';
$count = preg_match($regex, $head, $matches);
return isset($matches[1]) ? $matches[1] : "unknown";
}
Thursday, January 18, 2007
PHP function to get extension of a file
Here is a simple usefull function to get extension of a file
function getFileExtension($filename){
$dot = substr (strrchr ($filename, "."), 1);
return ($dot);
}
function getFileExtension($filename){
$dot = substr (strrchr ($filename, "."), 1);
return ($dot);
}
Subscribe to:
Posts (Atom)