Quantcast
Channel: Tópicos
Viewing all articles
Browse latest Browse all 14700

Download não resulta

$
0
0
Boas pessoal, sou novo em dreamweaver e PHP e isto ta a meter nervos já ;)
Alguém sabe como resolver este problema? Quando tento fazer download ele diz me que nenhum id foi passado...

Código (PHP):
<?php
// Make sure an ID was passed
if(isset($_GET['id'])) {
         // Get the ID$id
         $file_name= ($_GET['id']);
         // Make sure the ID is in fact a valid ID
if($file_name == NULL) {
         die('The name is invalid!');
}
else {
         // Connect to the database
         $dbLink = new mysqli('localhost', 'root', "mysql", 'dbtuts');
         if(mysqli_connect_errno()) {
                 die("MySQL connection failed: ".mysqli_connect_error());
         }
                 // Fetch the file information
         $query = "
                 SELECT `file`, `type`, `size`
                 FROM `tbl_uploads`
                 WHERE `file` = {$file}";
         $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);
                         header("Content-Type: ".$row['type']);
                         header("Content-Length: ".$row['size']);
                         header("Content-Disposition: attachment");
                         // disopsition = attachment to force download request
                         // Print data
                         echo $row['file'];
                 }
                 else {
                         echo 'Error! No file exists with that ID.';
                 }
                 // Free the mysqli resources
                 @mysqli_free_result($result);
         }
         else {
                 // if there is an error excuting the query
                 echo "Error! Query failed: <pre>{$dbLink->error}</pre>";
         }
         // close database connection
         @mysqli_close($dbLink);
}
}
else {
// if no ID passed
echo 'Error! No ID was passed.';
}
?>

Qualquer outra info necessária basta dizerem.

Cumps,
Slaxer13

Viewing all articles
Browse latest Browse all 14700