Posted by: denikus | March 28, 2008

File Manager dengan php

Sebelum kita membuat file manager kita harus mengetahui apa saja yang kita persiapkan . mungkin langsung saja …
Ada beberapa File yang harus dibuat , Diantaranya ..

- Membaca folder

function listdir($wdir) {
global $d, $nd,$pathext;
$hndl=opendir($wdir);
while($file=readdir($hndl)) {
if ($file==’.’ || $file==’..’) { continue; }
if (is_link($wdir.$file)) { continue; }

if (!hidecheck($file)) { continue; }
if (!UpPathOK($file.’/')) { continue; }
if (is_dir($wdir.$file)) {
if ($pathext != $file.’/’ ) {
$nd++;
$d[$nd]=$wdir.$file;
}
listdir($wdir.$file.”/”);
}
}
closedir($hndl);
return $d;
}

- Mengupload file
<?php

$uploaddir = ‘/uploads/’;
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);

echo
‘<pre>’;
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
echo “File berhasil diupload.\n”;
} else {
echo “File Gagal diupload!\n”;
}
echo ‘debug info:’;
print_r($_FILES);

print
“</pre>”;
?>
- Download file

<?php

$filename = $_GET['file'];

// required for IE, otherwise Content-disposition is ignored
if(ini_get(‘zlib.output_compression’))
ini_set(‘zlib.output_compression’, ‘Off’);

// addition by Jorg Weske
$file_extension = strtolower(substr(strrchr($filename,”.”),1));

if( $filename == “” )
{
echo “<html><title>eLouai’s Download Script</title><body>ERROR: download file NOT SPECIFIED. USE force-download.php?file=filepath</body></html>”;
exit;
} elseif ( ! file_exists( $filename ) )
{
echo “<html><title>eLouai’s Download Script</title><body>ERROR: File not found. USE force-download.php?file=filepath</body></html>”;
exit;
};
switch( $file_extension )
{
case “pdf”: $ctype=”application/pdf”; break;
case “exe”: $ctype=”application/octet-stream”; break;
case “zip”: $ctype=”application/zip”; break;
case “doc”: $ctype=”application/msword”; break;
case “xls”: $ctype=”application/vnd.ms-excel”; break;
case “ppt”: $ctype=”application/vnd.ms-powerpoint”; break;
case “gif”: $ctype=”image/gif”; break;
case “png”: $ctype=”image/png”; break;
case “jpeg”:
case “jpg”: $ctype=”image/jpg”; break;
default: $ctype=”application/force-download”;
}
header(“Pragma: public”); // required
header(“Expires: 0″);
header(“Cache-Control: must-revalidate, post-check=0, pre-check=0″);
header(“Cache-Control: private”,false); // required for certain browsers
header(“Content-Type: $ctype”);
// change, added quotes to allow spaces in filenames, by Rajkumar Singh
header(“Content-Disposition: attachment; filename=\”".basename($filename).”\”;” );
header(“Content-Transfer-Encoding: binary”);
header(“Content-Length: “.filesize($filename));
readfile(“$filename”);
exit();

?>

Makasih Semoga bermanfaat

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Categories

Follow

Get every new post delivered to your Inbox.