2015-01-08 2 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는 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.'; 
    } 
    ?> 

<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 no id was passed - 오류를 표시하는 이유는 무엇입니까?

이 프로그램은 파일을 mysql 데이터베이스에 업로드하고 파일을 나열한 다음 업로드 할 파일의 링크를 만듭니다. 하지만 몇 가지 문제가 있었는데, 다운로드 링크가 왜 오류를 보여?

+0

어떤 오류가 발생합니까? – Jonast92

+0

무엇이 오류입니까? –

+1

'isset ($ _ GET [ 'id'])'가 false이기 때문에? – 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>에 CHAGE한다.

href 파일이 제공된 파일과 일치하지 않습니다.

+0

예, 형제 님, 저는이 변경을했으나 작동하지 않습니다. – Sathishkumar