2015-01-08 19 views
-1
// this php program showing no id was passed error, why its showing this error, 
this program used for upload files into mysql database and list the files then create links for the uploaded file to download. but i had some problem, the download links shows error why?  

好心幫我解決這個問題...下載文件php程序顯示錯誤

listfile.php

<html> 
    <head> 
    <title>Paging</title> 
    </head> 
    <body> 
    <?php 
    $dbhost = 'localhost'; 
    $dbuser = 'sathishcst'; 
    $dbpass = 'geni7joy'; 
    $rec_limit = 10; 

    $conn = mysql_connect($dbhost, $dbuser, $dbpass); 
    if(! $conn) 
    { 
     die('Could not connect: ' . mysql_error()); 
    } 
    mysql_select_db('gat-india.com'); 
    /* Get total number of records */ 
    $sql = "select*from enquiry_info,resume_file "; 
    $retval = mysql_query($sql, $conn); 
    if(! $retval) 
    { 
     die('Could not get data: ' . mysql_error()); 
    } 
    $row = mysql_fetch_array($retval, MYSQL_NUM); 
    $rec_count = $row[0]; 

    if(isset($_GET{'page'})) 
    { 
     $page = $_GET{'page'} + 1; 
     $offset = $rec_limit * $page ; 
    } 
    else 
    { 
     $page = 0; 
     $offset = 0; 
    } 
    $left_rec = $rec_count - ($page * $rec_limit); 
    $sql = "select * from enquiry_info,resume_file where enquiry_info.id=resume_file.id\n" 
     . "ORDER BY `resume_file`.`id` DESC limit $offset, $rec_limit"; 
    /*$sql = "SELECT id,name,email,phone ". 
      "FROM pays ". 
      "LIMIT $offset, $rec_limit"; 
    */ 
    $retval = mysql_query($sql, $conn); 
    if(! $retval) 
    { 
     die('Could not get data: ' . mysql_error()); 
    } 
     echo '<table width="100%" border="1px" cellpadding="5px"> 
        <tr> 
         <td><b>EmpName</b></td> 
         <td><b>Email</b></td> 
         <td><b>Mobile</b></td> 
         <td><b>Name</b></td> 
        <!-- <td><b>Mime</b></td> 
         <td><b>Size (bytes)</b></td>--> 
         <td><b>Created</b></td> 
         <td><b>Download resume</b></td> 
        </tr>'; 

    while($row = mysql_fetch_array($retval, MYSQL_ASSOC)) 
    { 
     echo " 
        <tr> 
         <td>{$row['enqname']}</td> 
         <td>{$row['email']}</td> 
         <td>+91-{$row['phone']}</td> 
         <td>{$row['name']}</td> 
         <!-- <td>{$row['mime']}</td> 
         <td>{$row['size']}</td>--> 
         <td>{$row['created']}</td> 
         <td><a href='getfiles.php?id={$row['id']}'>{$row['name']}</a></td> 
        </tr>"; 
    } 
    echo '</table>'; 
    if($page > 0) 
    { 
     $last = $page - 2; 
     echo "<hr><center><a href=\"$_PHP_SELF?page=$last\">Last 10 Records</a> |"; 
     echo "<a href=\"$_PHP_SELF?page=$page\">Next 10 Records</a></center><hr>"; 
    } 
    else if($page == 0) 
    { 
     echo "<hr><br><center><a href=\"$_PHP_SELF?page=$page\">Next 10 Records</a>"; 
    } 
    else if($left_rec < $rec_limit) 
    { 
     $last = $page - 2; 
     echo "<hr><br><center><a href=\"$_PHP_SELF?page=$last\">Last 10 Records</a></center>"; 
    } 
    mysql_close($conn); 
    ?> 


// here the above list files working correctly... below only showing error. 

getfile.php

<?php 
    // Make sure an ID was passed 
    if(isset($_GET['id'])) { 
    // Get the ID 
     $id = intval($_GET['id']); 

     // Make sure the ID is in fact a valid ID 
     if($id <= 0) { 
      die('The ID is invalid!'); 
     } 
     else { 
      // Connect to the database 
      $dbLink = new mysqli('localhost', 'sathishcst', 'geni7joy', 'gat-india.com'); 
      if(mysqli_connect_errno()) { 
       die("MySQL connection failed: ". mysqli_connect_error()); 
      } 

      // Fetch the file information 
      $query = " 
       SELECT `mime`, `name`, `size`, `data` 
       FROM `resume_file` 
       WHERE `id` = {$id}"; 
      $result = $dbLink->query($query); 

      if($result) { 
       // Make sure the result is valid 
       if($result->num_rows == 1) { 
       // Get the row 
        $row = mysqli_fetch_assoc($result); 

        // Print headers 
        header("Content-Type: ". $row['mime']); 
        header("Content-Length: ". $row['size']); 
        header("Content-Disposition: attachment; filename=". $row['name']); 

        // Print data 
        echo $row['data']; 
       } 
       else { 
        echo 'Error! No image exists with that ID.'; 
       } 

       /Free the mysqli resources 
       @mysqli_free_result($result); 
      } 
      else { 
       echo "Error! Query failed: <pre>{$dbLink->error}</pre>"; 
      } 
      @mysqli_close($dbLink); 
     } 
    } 
    else { 
     echo 'Error! No ID was passed.'; 
    } 
    ?> 

PHP程序是顯示no id was passed-錯誤,爲什麼顯示此錯誤?

該程序用於將文件上傳到mysql數據庫並列出文件,然後創建上傳文件的鏈接進行下載。但我有一些問題,下載鏈接顯示錯誤爲什麼?

+0

發生什麼錯誤? – Jonast92

+0

什麼是錯誤..? –

+1

因爲'isset($ _ GET ['id'])'是錯誤的? – vaso123

回答

0

你應該listfile.php

<td><a href='getfiles.php?id={$row['id']}'>{$row['name']}</a></td>

檢查getfile.php鏈接的文件名,它恰克到

<td><a href='getfile.php?id={$row['id']}'>{$row['name']}</a></td>

href文件與提供的不匹配。

+0

是的,兄弟,我也做了這個改變,但這並不奏效。 – Sathishkumar