Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New Coder
    Join Date
    May 2012
    Posts
    14
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Download Script Error

    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
    PHP Code:
    <?

    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 Code:
    <?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)


    Is the webhosting affects download scripts with their file permissions?

    This just works fine in my xampp. please help. Thank you.

    REGARDS,
    MARK B.
    Last edited by markbaron15; 07-25-2012 at 07:32 PM.

  • #2
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,439
    Thanks
    62
    Thanked 537 Times in 524 Posts
    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.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #3
    New Coder
    Join Date
    May 2012
    Posts
    14
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Oh sorry. I edited the post. Please take a look at the screenshot.

  • #4
    Senior Coder
    Join Date
    Sep 2010
    Posts
    2,451
    Thanks
    17
    Thanked 275 Times in 275 Posts
    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?

  • #5
    New Coder
    Join Date
    May 2012
    Posts
    14
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by DrDOS View Post
    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.

  • #6
    Senior Coder
    Join Date
    Sep 2010
    Posts
    2,451
    Thanks
    17
    Thanked 275 Times in 275 Posts
    PHP Code:
    <?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.

  • #7
    New Coder
    Join Date
    May 2012
    Posts
    14
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by DrDOS View Post
    PHP Code:
    <?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?

  • #8
    New Coder
    Join Date
    May 2012
    Posts
    14
    Thanks
    4
    Thanked 0 Times in 0 Posts
    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!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •