...

View Full Version : Download Script Error



markbaron15
07-25-2012, 06: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 '|&nbsp;<a href="upload.php">Upload Files</a>';
}
if($session->isInstructor()){
echo '|&nbsp;<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.

tangoforce
07-25-2012, 07:00 PM
Unless you're prepared to post a larger version of that image that lets us read the text / errors then there is little we can say or do to help you.

You have given us virtually nothing to help us help you.

markbaron15
07-25-2012, 07:14 PM
Oh sorry. I edited the post. Please take a look at the screenshot.

DrDOS
07-25-2012, 09:36 PM
I may be being dumb, but I have to ask some questions, what kinds of files are these, filetypes, ect, and why are they being downloaded and not linked to by other means?

markbaron15
07-26-2012, 05:11 AM
I may be being dumb, but I have to ask some questions, what kinds of files are these, filetypes, ect, and why are they being downloaded and not linked to by other means?

Hi,

mostly any kind of files, the one being downloaded in my screenshot is a .docx file.

and i think i had already linked the files, because it works fine on xampp, that when i click on the file, it downloads directly.

i'm just thinking whether the webhost have the problem. im confused i don't have any idea.

Regards,
Mark B.

DrDOS
07-26-2012, 05:36 AM
<?php echo get_download_files_list(); ?>

I presume that that line generates links to the files. Is that right? I don't see anywhere that a mimetype is specified, and the file in question looks like it's a binary. So it may be misreading the mimetype.

markbaron15
07-26-2012, 07:30 AM
<?php echo get_download_files_list(); ?>

I presume that that line generates links to the files. Is that right? I don't see anywhere that a mimetype is specified, and the file in question looks like it's a binary. So it may be misreading the mimetype.

Yeah, i think i need to ask for the mimetype that was using by my webhost?

or any code that can specify a mimetype?

markbaron15
07-26-2012, 05:19 PM
Oh i got it working now.

I asked the webhost and they said output buffering is disabled on their server.

ob_start(); and ob_flush(); worked perfectly.

Thanks guys, you made me come up with ideas!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum