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 13 of 13
  1. #1
    New to the CF scene
    Join Date
    May 2012
    Posts
    8
    Thanks
    6
    Thanked 0 Times in 0 Posts

    no file download glitch

    I working with this file upload everything works but the download file.

    I'm getting the error message 'The file could not be located on the server'

    any ideas? Thanks!
    PHP Code:
    <?php # add_file.php
       // This page allows users to upload files to the server.

       // Set the page title and include the HTML header.
       
    $page_title 'Upload a File';
       include (
    'include/header.html');

       
    $counter 3// Number of files to allow for.

       
    if (isset($_POST['submitted'])) { // Handle the form.

           
    require_once ('mysql_connect.php'); // Connect to the database.

           
    for ($i 0$i $counter$i++) { // Handle each uploaded file.

               // Create index names to refer to the proper upload and description.
               
    $filename 'uploads' $i;
               
    $description 'description' $i;

               
    // Check for a file.
               
    if (isset($_FILES[$filename]) && ($_FILES[$filename]['error'] != 4)) { 

               
    // Check for a description (not required).
               
    if (!empty($_POST[$description])) {
                   
    $d "'" escape_data($_POST [$description]) . "'";

               } else {
                   
    $d 'NULL';
               }

               
    // Add the record to the dataabase.
               
    $query "INSERT INTO uploads (file_name, file_size, file_type,
                 description) VALUES ('{$_FILES[$filename]['name']}',{$_FILES [$filename]['size']},'{$_FILES [$filename]['type']}', $d)"
    ;
                 
    $result mysql_query ($query); 
                  
               if (
    $result) {

                   
    // Return the upload_id from the database.
                   
    $upload_id mysql_insert_id(); 

                   
    // Move the file over.
                   
    if( move_uploaded_file($_FILES[$filename]['tmp_name'], "upload/
                     $upload_id"
    )) {

                       echo 
    '<p>File number ' . ($i 1) . ' has been uploaded!</p>';

                   } else { 
    // File could not be moved.

                       
    echo '<p><font color="red">File number ' . ($i 1) . ' could not
                         be moved.</font></p>'
    ;

                       
    // Remove the record from the database.
                      
    $query "DELETE FROM uploads WHERE upload_id = $upload_id";
                       
    $result mysql_query ($query);

                       
    // Add more detailed error reporting, if desired.

                       


                   } else { 
    // If the query did not run OK.
                       
    echo '<p><font color="red">Your submission could not be processed
                         due to a system error. We apologize for any 
                         inconvenience.</font></p>'
    ;
                       
    // Print the query and invoke the mysql_error() function to debug.
                   
    }

               } 
    // End of if (isset($the_file)...

           
    // End of FOR loop.

           
    mysql_close(); // Close the database connection.

       
    }
       
    ?>
       <form enctype="multipart/form-data" action="add_file.php" method="post">

           <fieldset><legend>Fill out the form to upload a file:</legend>
           <input type="hidden" name="MAX_FILE_SIZE" value="5242880" /> 

           <?php // Create the inputs.
           
    for ($i 0$i $counter$i++) {
               echo 
    '<p><b>File:</b> <input type="file" name="uploads' $i '" /></p>
           <p><b>Description:</b> <textarea name="description' 
    $i '" cols="40"
             rows="5"></textarea></p><br />
           '
    ;
           }
           
    ?>

           </fieldset>
           <input type="hidden" name="submitted" value="TRUE" />
           <div align="center"><input type="submit" name="submit" value="Submit" /></div>

       </form>
       <?php
       
    include ('include/footer.html');
       
    ?>
    PHP Code:
    <?php # view_files.php
       // This page displays the files uploaded to the server.

       // Set the page title and include the HTML header.
       
    $page_title 'View Files';
       include (
    'include/header.html');

       require_once (
    'mysql_connect.php');

       
    $first TRUE// Initialize the variable.

       // Query the database.
       
    $query "SELECT upload_id, file_name, ROUND(file_size/1024) AS fs, description, DATE_FORMAT(date_entered, '%M %e, %Y') AS d FROM uploads ORDER BY date_entered DESC";
       
    $result mysql_query ($query); 


       
    // Display all URLs.
       
    while ($row mysql_fetch_array($resultMYSQL_ASSOC)) {

            
    // If this is the first record, create the table header.
            
    if ($first) {
                echo 
    '<table border="0" width="100%" cellspacing="3" cellpadding="3" align="center">
            <tr>
                <td align="left" width="20%"><font size="+1">File Name</font></td>
                <td align="left" width="40%"><font size="+1">Description</font></td> 
                <td align="center" width="20%"><font size="+1">File Size</font></td>
                <td align="left" width="20%"><font size="+1">Upload Date</font></td>
            </tr>'
    ;
                
    $first FALSE// Once record has been returned.

            
    // End of $first IF.

            // Display each record.
            
    echo " <tr>
                <td align=\"left\"><a href=\"download_file.php?uid=<?php{$row['upload_id']};?>\">{$row['file_name']}</a></td>
                <td align=\"left\">" 
    stripslashes($row ['description']) . "</td>
                <td align=\"center\">{$row ['fs']}kb</td>
                <td align=\"left\">{$row ['d']}</td>
                <td align=\"left\"><a href=\"edit_file.php?uid={$row['upload_id']}\">edit</a></td>
            </tr>\n"
    ;

       } 
    // End of while loop.

       // If no records were diplayed...
       
    if ($first) {
            echo 
    '<div align="center">There are currently no files to be viewed.</div>';
       } else {
            echo 
    '</table>'// Close the table.
       
    }

       
    mysql_close(); // Close the database connetion.
       
    include ('include/footer.html');
       
    ?>
    PHP Code:
       <?php # download_file.php
       // This page handles file downloads through headers.

       // Check for an upload_id.
       
    if (isset($_GET['uid'])) {
           
    $uid = (int) $_GET['uid'];
       } else { 
    // Big problem!
           
    $uid 0;
       }

       if (
    $uid 0) { // OK to proceed!

           
    require_once ('mysql_connect.php');
           
           
    // Connect to the dataabase.

           // Get the information for this file.
           
    $query "SELECT 'file_name', 'file_size', 'file_type' FROM 'uploads' WHERE
             upload_id=$uid"
    ;
           
    $result mysql_query ($query);

           list (
    $fn$fs$ft) = mysql_fetch_array ($resultMYSQL_NUM);
           
    mysql_close(); // Close the database connection.

           // Determine the file name on the server.
           
    $the_file 'upload' $uid

           
    // Check if it exists.
           
    if (file_exists ($the_file)) { 

               
    // Send the file.
               
    header ('content-type: application/octet-stream');
               
    header ('content-description: File Transfer');
               
    header ("Content-disposition: attachment; filename=\"$fn\"\n"); 
               
    header ("Content-Length: $fs\n");
               
    header ("Content-Type: $ft\n");
               

               
    readfile ($the_file); 

           } else { 
    // File doesn't exist.
               
    $page_title 'File Download';
               include (
    'include/header.html');
               echo 
    '<p><font color="red">The file could not be located on the server.
                 We apologize for any inconvenience.</font></p>'
    ;
               include (
    'include/footer.html');
           }

       } else { 
    // No valid upload ID.
           
    $page_title 'File Download';
           include (
    'include/header.html');
           echo 
    '<p><font color="red">Please select a valid file to download.
             </font></p>'
    ;
           include (
    'include/footer.html');
       }
       
    ?>

  • #2
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,090
    Thanks
    51
    Thanked 506 Times in 493 Posts
    Quote Originally Posted by rhs49010 View Post
    I working with this file upload everything works but the download file.

    I'm getting the error message 'The file could not be located on the server'

    any ideas? Thanks!
    PHP Code:
    <?php # add_file.php
       // This page allows users to upload files to the server.
                   
    if( move_uploaded_file($_FILES[$filename]['tmp_name'], "upload/
                     $upload_id"
    ))
    PHP Code:
       <?php # download_file.php
       // This page handles file downloads through headers.

           
    $the_file 'upload' $uid

           
    // Check if it exists.
           
    if (file_exists ($the_file)) {
    You have a little problem with your file names.

    Look at this:


    Not only do you have 3 tabs and several spaces after them between 'upload/' and your $uid variable in your upload script, you also have a missing / in your download script between them.

    Inside quote marks (double " or single ') you cannot use tabs or spaces for filenames / file paths as they will be used IN THE FILE NAME. It might look prettier in your editor but it will break your file paths.

    Your code should be like this:
    PHP Code:
    <?php # add_file.php
       // This page allows users to upload files to the server.
                   
    if( move_uploaded_file($_FILES[$filename]['tmp_name'], 'upload/' .$upload_id))
    PHP Code:
       <?php # download_file.php
       // This page handles file downloads through headers.

           
    $the_file 'upload/' $uid

           
    // Check if it exists.
           
    if (file_exists ($the_file)) {
    My helpful sig is on vacation trying to loose some weight. It got a bit fat and caused a few problems but it will be back at some point!

  • Users who have thanked tangoforce for this post:

    rhs49010 (08-21-2013)

  • #3
    Senior Coder
    Join Date
    Sep 2010
    Posts
    1,899
    Thanks
    15
    Thanked 226 Times in 226 Posts
    This is goofy.
    PHP Code:
               header ("Content-disposition: attachment; filename=\"$fn\"\n"); 
               
    header ("Content-Length: $fs\n");
               
    header ("Content-Type: $ft\n");

    More like this:

               
    header ("Content-disposition: attachment; filename=".$fn); 
               
    header ("Content-Length: ".$fs);
               
    header ("Content-Type: ".$ft); 
    The \n means go to a new line, which you don't need there.
    Welcome to http://www.myphotowizard.net

    where you can edit images, make a photo calendar, add text to images, and do much more.


    When you know what you're doing it's called Engineering, when you don't know, it's called Research and Development. And you can always charge more for Research and Development.

  • Users who have thanked DrDOS for this post:

    rhs49010 (08-21-2013)

  • #4
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,090
    Thanks
    51
    Thanked 506 Times in 493 Posts
    Quote Originally Posted by DrDOS View Post
    This is goofy.
    PHP Code:
    More like this:

               
    header ("Content-disposition: attachment; filename=".$fn); 
    Also goofy as you've just removed the quote marks from the filename
    My helpful sig is on vacation trying to loose some weight. It got a bit fat and caused a few problems but it will be back at some point!

  • #5
    Senior Coder
    Join Date
    Sep 2010
    Posts
    1,899
    Thanks
    15
    Thanked 226 Times in 226 Posts
    Quote Originally Posted by tangoforce View Post
    Also goofy as you've just removed the quote marks from the filename
    If the file doesn't have spaces it will work just fine, but!
    PHP Code:
      header ("Content-disposition: attachment; filename=\"".$fn."\""); 
    That will put them in if needed.
    Welcome to http://www.myphotowizard.net

    where you can edit images, make a photo calendar, add text to images, and do much more.


    When you know what you're doing it's called Engineering, when you don't know, it's called Research and Development. And you can always charge more for Research and Development.

  • #6
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,090
    Thanks
    51
    Thanked 506 Times in 493 Posts
    Quote Originally Posted by DrDOS View Post
    PHP Code:
      header ("Content-disposition: attachment; filename=\"".$fn."\""); 
    If you're concat'ing then that should really be using single quotes:

    PHP Code:
      header ('Content-disposition: attachment; filename="' .$fn .'"'); 
    Otherwise..

    PHP Code:
      header ("Content-disposition: attachment; filename=\"$fn\""); 
    Singles use less cpu cycles, doubles allow you to avoid jumping in and out
    My helpful sig is on vacation trying to loose some weight. It got a bit fat and caused a few problems but it will be back at some point!

  • Users who have thanked tangoforce for this post:

    rhs49010 (08-21-2013)

  • #7
    New to the CF scene
    Join Date
    May 2012
    Posts
    8
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Okay I made the changes BUT...

    Take a look at the modified code.
    I made the changes every one suggested, I think.

    Everything but the download file works, back to square one.

    I really appreciate everyones help!

    any more ideas?

    PHP Code:
    <?php # add_file.php
       // This page allows users to upload files to the server.

       // Set the page title and include the HTML header.
       
    $page_title 'Upload a File';
       include (
    'include/header.html');

       
    $counter 3// Number of files to allow for.

       
    if (isset($_POST['submitted'])) { // Handle the form.

           
    require_once ('mysql_connect.php'); // Connect to the database.

           
    for ($i 0$i $counter$i++) { // Handle each uploaded file.

               // Create index names to refer to the proper upload and description.
               
    $filename 'uploads' $i;
               
    $description 'description' $i;

               
    // Check for a file.
               
    if (isset($_FILES[$filename]) && ($_FILES[$filename]['error'] != 4)) { 

               
    // Check for a description (not required).
               
    if (!empty($_POST[$description])) {
                   
    $d "'" escape_data($_POST [$description]) . "'";

               } else {
                   
    $d 'NULL';
               }

               
    // Add the record to the dataabase.
               
    $query "INSERT INTO uploads (file_name, file_size, file_type,
                 description) VALUES ('{$_FILES[$filename]['name']}',{$_FILES [$filename]['size']},'{$_FILES [$filename]['type']}', $d)"
    ;
                 
    $result mysql_query ($query); 
                  
               if (
    $result) {

                   
    // Return the upload_id from the database.
                   
    $upload_id mysql_insert_id(); 

                   
    // Move the file over.
                   
    if( move_uploaded_file($_FILES[$filename]['tmp_name'], 'upload/' .$upload_id)) {

                       echo 
    '<p>File number ' . ($i 1) . ' has been uploaded!</p>';

                   } else { 
    // File could not be moved.

                       
    echo '<p><font color="red">File number ' . ($i 1) . ' could not
                         be moved.</font></p>'
    ;

                       
    // Remove the record from the database.
                      
    $query "DELETE FROM uploads WHERE upload_id = $upload_id";
                       
    $result mysql_query ($query);

                       
    // Add more detailed error reporting, if desired.

                       


                   } else { 
    // If the query did not run OK.
                       
    echo '<p><font color="red">Your submission could not be processed
                         due to a system error. We apologize for any 
                         inconvenience.</font></p>'
    ;
                       
    // Print the query and invoke the mysql_error() function to debug.
                   
    }

               } 
    // End of if (isset($the_file)...

           
    // End of FOR loop.

           
    mysql_close(); // Close the database connection.

       
    }
       
    ?>
       <form enctype="multipart/form-data" action="add_file.php" method="post">

           <fieldset><legend>Fill out the form to upload a file:</legend>
           <input type="hidden" name="MAX_FILE_SIZE" value="5242880" /> 

           <?php // Create the inputs.
           
    for ($i 0$i $counter$i++) {
               echo 
    '<p><b>File:</b> <input type="file" name="uploads' $i '" /></p>
           <p><b>Description:</b> <textarea name="description' 
    $i '" cols="40"
             rows="5"></textarea></p><br />
           '
    ;
           }
           
    ?>

           </fieldset>
           <input type="hidden" name="submitted" value="TRUE" />
           <div align="center"><input type="submit" name="submit" value="Submit" /></div>

       </form>
       <?php
       
    include ('include/footer.html');
       
    ?>
    PHP Code:
    <?php # view_files.php
       // This page displays the files uploaded to the server.

       // Set the page title and include the HTML header.
       
    $page_title 'View Files';
       include (
    'include/header.html');

       require_once (
    'mysql_connect.php');

       
    $first TRUE// Initialize the variable.

       // Query the database.
       
    $query "SELECT upload_id, file_name, ROUND(file_size/1024) AS fs, description, DATE_FORMAT(date_entered, '%M %e, %Y') AS d FROM uploads ORDER BY date_entered DESC";
       
    $result mysql_query ($query); 


       
    // Display all URLs.
       
    while ($row mysql_fetch_array($resultMYSQL_ASSOC)) {

            
    // If this is the first record, create the table header.
            
    if ($first) {
                echo 
    '<table border="0" width="100%" cellspacing="3" cellpadding="3" align="center">
            <tr>
                <td align="left" width="20%"><font size="+1">File Name</font></td>
                <td align="left" width="40%"><font size="+1">Description</font></td> 
                <td align="center" width="20%"><font size="+1">File Size</font></td>
                <td align="left" width="20%"><font size="+1">Upload Date</font></td>
            </tr>'
    ;
                
    $first FALSE// Once record has been returned.

            
    // End of $first IF.

            // Display each record.
            
    echo " <tr>
                <td align=\"left\"><a href=\"download_file.php?uid=<?php{$row['upload_id']};?>\">{$row['file_name']}</a></td>
                <td align=\"left\">" 
    stripslashes($row ['description']) . "</td>
                <td align=\"center\">{$row ['fs']}kb</td>
                <td align=\"left\">{$row ['d']}</td>
                <td align=\"left\"><a href=\"edit_file.php?uid={$row['upload_id']}\">edit</a></td>
            </tr>\n"
    ;

       } 
    // End of while loop.

       // If no records were diplayed...
       
    if ($first) {
            echo 
    '<div align="center">There are currently no files to be viewed.</div>';
       } else {
            echo 
    '</table>'// Close the table.
       
    }

       
    mysql_close(); // Close the database connetion.
       
    include ('include/footer.html');
       
    ?>
    PHP Code:
       <?php # download_file.php
       // This page handles file downloads through headers.

       // Check for an upload_id.
       
    if (isset($_GET[uid])) {
           
    $uid = (int) $_GET['uid'];
       } else { 
    // Big problem!
           
    $uid 0;
       }

       if (
    $uid 0) { // OK to proceed!

           
    require_once ('mysql_connect.php');
           
           
    // Connect to the dataabase.

           // Get the information for this file.
           
    $query "SELECT 'file_name', 'file_size', 'file_type' FROM 'uploads' WHERE
             upload_id = $uid"
    ;
           
    $result mysql_query ($query);

           list (
    $fn$fs$ft) = mysql_fetch_array ($resultMYSQL_NUM);
           
    mysql_close(); // Close the database connection.

           // Determine the file name on the server.
          
    $the_file 'upload/' $uid

           
    // Check if it exists.
          
    if (file_exists ($the_file)) { 

               
    // Send the file.
               
    header ("content-type: application/octet-stream");
               
    header ("content-description: File Transfer");
              
    header ("Content-disposition: attachment; filename=".$fn); 
               
    header ("Content-Length: ".$fs);
               
    header ("Content-Type: ".$ft);
               

               
    readfile ($the_file); 

           } else { 
    // File doesn't exist.
               
    $page_title 'File Download';
               include (
    'include/header.html');
               echo 
    '<p><font color="red">The file could not be located on the server.
                 We apologize for any inconvenience.</font></p>'
    ;
               include (
    'include/footer.html');
           }

       } else { 
    // No valid upload ID.
           
    $page_title 'File Download';
           include (
    'include/header.html');
           echo 
    '<p><font color="red">Please select a valid file to download.
             </font></p>'
    ;
           include (
    'include/footer.html');
       }
       
    ?>

  • #8
    Senior Coder
    Join Date
    Sep 2010
    Posts
    1,899
    Thanks
    15
    Thanked 226 Times in 226 Posts
    How are you accessing this download.php? It's usually done with a web link,
    <a href="download.php">Download your file.</a>
    although, if it's an image it could be the source of an img element.
    Welcome to http://www.myphotowizard.net

    where you can edit images, make a photo calendar, add text to images, and do much more.


    When you know what you're doing it's called Engineering, when you don't know, it's called Research and Development. And you can always charge more for Research and Development.

  • Users who have thanked DrDOS for this post:

    rhs49010 (08-22-2013)

  • #9
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,090
    Thanks
    51
    Thanked 506 Times in 493 Posts
    When you upload the file, do you definitely see this message / code run?:

    PHP Code:
    echo '<p>File number ' . ($i 1) . ' has been uploaded!</p>'
    My helpful sig is on vacation trying to loose some weight. It got a bit fat and caused a few problems but it will be back at some point!

  • #10
    New to the CF scene
    Join Date
    May 2012
    Posts
    8
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by DrDOS View Post
    How are you accessing this download.php? It's usually done with a web link,
    <a href="download.php">Download your file.</a>
    although, if it's an image it could be the source of an img element.
    The file name is linked from the view_files.php file.
    example... url.com/download_file.php?uid=106

    I set a var_dump (uid) after the isset function in the download file
    and it's passing the correct value to the download page
    but I keep getting the predefined error message...
    The file could not be located on the server. We apologize for any inconvenience.

    This is the latest changes to the code

    PHP Code:
    <?php # add_file.php
       // This page allows users to upload files to the server.

       // Set the page title and include the HTML header.
       
    $page_title 'Upload a File';
       include (
    'include/header.html');

       
    $counter 3// Number of files to allow for.

       
    if (isset($_POST['submitted'])) { // Handle the form.

           
    require_once ('mysql_connect.php'); // Connect to the database.

           
    for ($i 0$i $counter$i++) { // Handle each uploaded file.

               // Create index names to refer to the proper upload and description.
               
    $filename 'uploads' $i;
               
    $description 'description' $i;

               
    // Check for a file.
               
    if (isset($_FILES[$filename]) && ($_FILES[$filename]['error'] != 4)) { 

               
    // Check for a description (not required).
               
    if (!empty($_POST[$description])) {
                   
    $d "'" escape_data($_POST [$description]) . "'";

               } else {
                   
    $d 'NULL';
               }

               
    // Add the record to the dataabase.
               
    $query "INSERT INTO uploads (file_name, file_size, file_type,
                 description) VALUES ('{$_FILES[$filename]['name']}',{$_FILES [$filename]['size']},'{$_FILES [$filename]['type']}', $d)"
    ;
                 
    $result mysql_query ($query); 
                  
               if (
    $result) {

                   
    // Return the upload_id from the database.
                   
    $upload_id mysql_insert_id(); 

                   
    // Move the file over.
                   
    if( move_uploaded_file($_FILES[$filename]['tmp_name'], 'upload/'.$upload_id)) {

                       echo 
    '<p>File number ' . ($i 1) . ' has been uploaded!</p>';

                   } else { 
    // File could not be moved.

                       
    echo '<p><font color="red">File number ' . ($i 1) . ' could not
                         be moved.</font></p>'
    ;

                       
    // Remove the record from the database.
                      
    $query "DELETE FROM uploads WHERE upload_id = $upload_id";
                       
    $result mysql_query ($query);

                       
    // Add more detailed error reporting, if desired.

                       


                   } else { 
    // If the query did not run OK.
                       
    echo '<p><font color="red">Your submission could not be processed
                         due to a system error. We apologize for any 
                         inconvenience.</font></p>'
    ;
                       
    // Print the query and invoke the mysql_error() function to debug.
                   
    }

               } 
    // End of if (isset($the_file)...

           
    // End of FOR loop.

           
    mysql_close(); // Close the database connection.

       
    }
       
    ?>
       <form enctype="multipart/form-data" action="add_file.php" method="post">

           <fieldset><legend>Fill out the form to upload a file:</legend>
           <input type="hidden" name="MAX_FILE_SIZE" value="5242880" /> 

           <?php // Create the inputs.
           
    for ($i 0$i $counter$i++) {
               echo 
    '<p><b>File:</b> <input type="file" name="uploads' $i '" /></p>
           <p><b>Description:</b> <textarea name="description' 
    $i '" cols="40"
             rows="5"></textarea></p><br />
           '
    ;
           }
           
    ?>

           </fieldset>
           <input type="hidden" name="submitted" value="TRUE" />
           <div align="center"><input type="submit" name="submit" value="Submit" /></div>

       </form>
       <?php
       
    include ('include/footer.html');
       
    ?>
    PHP Code:
    <?php # view_files.php
       // This page displays the files uploaded to the server.

       // Set the page title and include the HTML header.
       
    $page_title 'View Files';
       include (
    'include/header.html');

       require_once (
    'mysql_connect.php');

       
    $first TRUE// Initialize the variable.

       // Query the database.
       
    $query "SELECT upload_id, file_name, ROUND(file_size/1024) AS fs, description, DATE_FORMAT(date_entered, '%M %e, %Y') AS d FROM uploads ORDER BY date_entered DESC";
       
    $result mysql_query ($query); 


       
    // Display all URLs.
       
    while ($row mysql_fetch_array($resultMYSQL_ASSOC)) {

            
    // If this is the first record, create the table header.
            
    if ($first) {
                echo 
    '<table border="0" width="100%" cellspacing="3" cellpadding="3" align="center">
            <tr>
                <td align="left" width="20%"><font size="+1">File Name</font></td>
                <td align="left" width="40%"><font size="+1">Description</font></td> 
                <td align="center" width="20%"><font size="+1">File Size</font></td>
                <td align="left" width="20%"><font size="+1">Upload Date</font></td>
            </tr>'
    ;
                
    $first FALSE// Once record has been returned.

            
    // End of $first IF.

            // Display each record.
            
    echo " <tr>
                <td align=\"left\"><a href=\"download_file.php?uid={$row['upload_id']}\">{$row['file_name']}</a></td>
                <td align=\"left\">" 
    stripslashes($row ['description']) . "</td>
                <td align=\"center\">{$row ['fs']}kb</td>
                <td align=\"left\">{$row ['d']}</td>
                <td align=\"left\"><a href=\"edit_file.php?uid={$row['upload_id']}\">edit</a></td>
            </tr>\n"
    ;

       } 
    // End of while loop.

       // If no records were diplayed...
       
    if ($first) {
            echo 
    '<div align="center">There are currently no files to be viewed.</div>';
       } else {
            echo 
    '</table>'// Close the table.
       
    }

       
    mysql_close(); // Close the database connetion.
       
    include ('include/footer.html');
       
    ?>
    PHP Code:
       <?php # download_file.php
       // This page handles file downloads through headers.

       // Check for an upload_id.
       
    if (isset($_GET['uid'])) {
           
    $uid = (int) $_GET['uid'];
           
    var_dump($uid);
       } else { 
    // Big problem!
           
    $uid 0;
       }

       if (
    $uid 0) { // OK to proceed!

           
    require_once ('mysql_connect.php');
           
           
    // Connect to the dataabase.

           // Get the information for this file.
           
    $query "SELECT 'file_name', 'file_size', 'file_type' FROM 'uploads' WHERE
             upload_id = $uid"
    ;
           
    $result mysql_query ($query);

           list (
    $fn$fs$ft) = mysql_fetch_array ($resultMYSQL_NUM);
           
    mysql_close(); // Close the database connection.

           // Determine the file name on the server.
          
    $the_file "upload $uid"

           
    // Check if it exists.
          
    if (file_exists ($the_file)) { 

               
    // Send the file.
              
               
    header ("content-description: File Transfer");
              
    header ("Content-disposition: attachment;filename=$fn"); 
               
    header ("Content-Length:$fs");
               
    header ("Content-Type: $ft");
               

               
    readfile ($the_file); 

           } else { 
    // File doesn't exist.
               
    $page_title 'File Download';
               include (
    'include/header.html');
               echo 
    '<p><font color="red">The file could not be located on the server.
                 We apologize for any inconvenience.</font></p>'
    ;
               include (
    'include/footer.html');
           }

       } else { 
    // No valid upload ID.
           
    $page_title 'File Download';
           include (
    'include/header.html');
           echo 
    '<p><font color="red">Please select a valid file to download.
             </font></p>'
    ;
           include (
    'include/footer.html');
       }
       
    ?>
    someone mentioned my ...
    PHP Code:
     $the_file "upload $uid"
    is wrong but I've tried many different ways, still not downloading.

    F.Y.I. If I upload a .pdf or .txt or .jpg nothing downloads

  • #11
    New to the CF scene
    Join Date
    May 2012
    Posts
    8
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by tangoforce View Post
    When you upload the file, do you definitely see this message / code run?:

    PHP Code:
    echo '<p>File number ' . ($i 1) . ' has been uploaded!</p>'
    I'm not sure what you mean by code run?:

    The upload file works like it is suppose to.

    Thanks

  • #12
    Senior Coder
    Join Date
    Sep 2010
    Posts
    1,899
    Thanks
    15
    Thanked 226 Times in 226 Posts
    When you're writing a download.php you can't leave any spaces or content before or after the php tags, none, or the file will be corrupt.
    Welcome to http://www.myphotowizard.net

    where you can edit images, make a photo calendar, add text to images, and do much more.


    When you know what you're doing it's called Engineering, when you don't know, it's called Research and Development. And you can always charge more for Research and Development.

  • Users who have thanked DrDOS for this post:

    rhs49010 (08-22-2013)

  • #13
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,090
    Thanks
    51
    Thanked 506 Times in 493 Posts
    Quote Originally Posted by rhs49010 View Post
    I'm not sure what you mean by code run?:
    It's quite simple. Does php echo that line to the browser or not?
    My helpful sig is on vacation trying to loose some weight. It got a bit fat and caused a few problems but it will be back at some point!


  •  

    Posting Permissions

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