markbaron15
07-25-2012, 05:57 PM
Hi,
I need help for my script to work fine.
I have my download script on my xampp (PHP version 5.3.5) and it is working fine.
Here is the code and some screenies.
in dl_functions.php
<?
function set_size($size)
{
$kb = 1024;
$mb = 1024 * $kb;
$gb = 1024 * $mb;
$tb = 1024 * $gb;
if ($size < $kb) return $size.' B';
elseif ($size < $mb) return round($size/$kb,2).' KB';
elseif ($size < $gb) return round($size/$mb,2).' MB';
elseif ($size < $tb) return round($size/$gb,2).' GB';
else return round($size/$tb,2).' TB';
}
function get_download_files_list()
{
global $download_dirs, $SLINE;
$files_list = "";
$i = 0;
$from_path = dirname(__FILE__)."/".$download_dirs;
if (is_dir($from_path)) {
chdir($from_path);
$handle = opendir('.');
while (($file = readdir($handle)) !== false)
{
if (($file != ".") && ($file != "..") && is_file($file)) {
$files_list .= '<tr><td width="75%"><a href="viewfiles.php?'.$SLINE.'&file='.htmlentities(urlencode(basename($file))).'">'.basename($file).'</a></td><td>'.set_size(filesize($file)).'</td><td><input type="checkbox" name="deleteMe[]" value="'.basename($file).'"></tr>';
}
}
closedir($handle);
}
return $files_list;
}
function do_download($file)
{
global $download_dirs;
$file_name = dirname(__FILE__)."/".$download_dirs.$file;
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Pragma: public");
header("Content-Type: application/save");
header("Content-Length: ".filesize($file_name));
header("Content-Disposition: attachment; filename=\"$file\"");
header("Content-Transfer-Encoding: binary");
readfile($file_name);
exit;
}
?>
and in viewfiles.php
<?php
include 'include/session.php';
include 'templates/include/header.php';
include 'include/menubar.php';
include("config.php");
include("dl_functions.php");
$from_path = dirname(__FILE__)."/".$download_dirs;
if (is_dir($from_path)) {
chdir($from_path);
$handle = opendir('.');
while (($file = readdir($handle)) !== false)
{
if (($file != ".") && ($file != "..") && is_file($file)) {
if(isset($_POST['deleteMe']) && count($_POST['deleteMe']) > 0){
foreach($_POST['deleteMe'] as $file){
if(file_exists($from_path.$file)){
unlink($from_path.$file);
}
}
}
}
}
//unset($_POST['deleteMe']);
}
if (isset($_GET["file"])) do_download($_GET["file"]);
?>
<div id="container">
<div id="content">
<h1>VIEW FILES</h1>
<a href="admin.php">Back</a>
<?php if($session->isAdmin()){
echo '| <a href="upload.php">Upload Files</a>';
}
if($session->isInstructor()){
echo '| <a href="upload.php">Upload Files</a>';
}
?>
<br />
<form action="viewfiles.php" method="post">
<table class="main_table" align="center" style="width: auto;">
<tr>
<td colspan="1"><b>Download files list</b></td>
<td colspan="1"><b>Size</b></td>
<td colspan="1"><b>Select</b></td>
</tr>
<?php echo get_download_files_list(); ?>
</table>
<center><button type="submit" name="submit" value="submit" onclick="return confirm('Note: This will delete selected files. None otherwise.')">Delete selected</button>
<button type="reset" name="reset">Reset</button></center>
</form>
<br />
</div>
<?php include 'templates/include/footer.php'; ?>
</div>
I uploaded my site into x10hosting.com (w/ PHP version 5.3.10), then the script gave me this (See screenshot)
http://img198.imageshack.us/img198/4276/441s.png
Is the webhosting affects download scripts with their file permissions?
This just works fine in my xampp. please help. Thank you.
REGARDS,
MARK B.
I need help for my script to work fine.
I have my download script on my xampp (PHP version 5.3.5) and it is working fine.
Here is the code and some screenies.
in dl_functions.php
<?
function set_size($size)
{
$kb = 1024;
$mb = 1024 * $kb;
$gb = 1024 * $mb;
$tb = 1024 * $gb;
if ($size < $kb) return $size.' B';
elseif ($size < $mb) return round($size/$kb,2).' KB';
elseif ($size < $gb) return round($size/$mb,2).' MB';
elseif ($size < $tb) return round($size/$gb,2).' GB';
else return round($size/$tb,2).' TB';
}
function get_download_files_list()
{
global $download_dirs, $SLINE;
$files_list = "";
$i = 0;
$from_path = dirname(__FILE__)."/".$download_dirs;
if (is_dir($from_path)) {
chdir($from_path);
$handle = opendir('.');
while (($file = readdir($handle)) !== false)
{
if (($file != ".") && ($file != "..") && is_file($file)) {
$files_list .= '<tr><td width="75%"><a href="viewfiles.php?'.$SLINE.'&file='.htmlentities(urlencode(basename($file))).'">'.basename($file).'</a></td><td>'.set_size(filesize($file)).'</td><td><input type="checkbox" name="deleteMe[]" value="'.basename($file).'"></tr>';
}
}
closedir($handle);
}
return $files_list;
}
function do_download($file)
{
global $download_dirs;
$file_name = dirname(__FILE__)."/".$download_dirs.$file;
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Pragma: public");
header("Content-Type: application/save");
header("Content-Length: ".filesize($file_name));
header("Content-Disposition: attachment; filename=\"$file\"");
header("Content-Transfer-Encoding: binary");
readfile($file_name);
exit;
}
?>
and in viewfiles.php
<?php
include 'include/session.php';
include 'templates/include/header.php';
include 'include/menubar.php';
include("config.php");
include("dl_functions.php");
$from_path = dirname(__FILE__)."/".$download_dirs;
if (is_dir($from_path)) {
chdir($from_path);
$handle = opendir('.');
while (($file = readdir($handle)) !== false)
{
if (($file != ".") && ($file != "..") && is_file($file)) {
if(isset($_POST['deleteMe']) && count($_POST['deleteMe']) > 0){
foreach($_POST['deleteMe'] as $file){
if(file_exists($from_path.$file)){
unlink($from_path.$file);
}
}
}
}
}
//unset($_POST['deleteMe']);
}
if (isset($_GET["file"])) do_download($_GET["file"]);
?>
<div id="container">
<div id="content">
<h1>VIEW FILES</h1>
<a href="admin.php">Back</a>
<?php if($session->isAdmin()){
echo '| <a href="upload.php">Upload Files</a>';
}
if($session->isInstructor()){
echo '| <a href="upload.php">Upload Files</a>';
}
?>
<br />
<form action="viewfiles.php" method="post">
<table class="main_table" align="center" style="width: auto;">
<tr>
<td colspan="1"><b>Download files list</b></td>
<td colspan="1"><b>Size</b></td>
<td colspan="1"><b>Select</b></td>
</tr>
<?php echo get_download_files_list(); ?>
</table>
<center><button type="submit" name="submit" value="submit" onclick="return confirm('Note: This will delete selected files. None otherwise.')">Delete selected</button>
<button type="reset" name="reset">Reset</button></center>
</form>
<br />
</div>
<?php include 'templates/include/footer.php'; ?>
</div>
I uploaded my site into x10hosting.com (w/ PHP version 5.3.10), then the script gave me this (See screenshot)
http://img198.imageshack.us/img198/4276/441s.png
Is the webhosting affects download scripts with their file permissions?
This just works fine in my xampp. please help. Thank you.
REGARDS,
MARK B.