Download file from database and auto save and overwrite

I want to make php page to auto download from database auto save and to overwrite it…so i use this php code and it is not i think the the mistake is at myhand…i am a junior to the php…so help me how to fix this problem…

my error code is

Error! A file was not sent!
( ! ) Notice: Undefined variable: row1 in C:\wamp\www\make txt file\Auto download and Auto save .php on line 33 Call Stack #TimeMemoryFunctionLocation 10.0007149816{main}( )…\Auto download and Auto save .php:0 The ID is invalid!

I WANT TO DOWNLOAD Name: 123.txt Size: 2Kb that is the my code:-


<?php // Check if a file has been uploaded if(isset($_FILES['uploaded_file'])) { // Make sure the file was sent without errors if($_FILES['uploaded_file']['error'] == 0) { // Connect to the database $dbLink = new mysqli("","root","blabla",'blabla');// if(mysqli_connect_errno()) { die("MySQL connection failed: ". mysqli_connect_error()); } // Gather all required data $name = $dbLink->real_escape_string($_FILES['uploaded_file']['name']); $mime = $dbLink->real_escape_string($_FILES['uploaded_file']['type']); $data = $dbLink->real_escape_string(file_get_contents($_FILES ['uploaded_file']['tmp_name'])); $size = intval($_FILES['uploaded_file']['size']); // Create the SQL query $query = "INSERT INTO file (`name`,`mime`,`size`,`data`,`created`) VALUES ('{$name}', '{$mime}', '{$size}', '{$data}', NOW())"; // Execute the query $resulta = $dbLink->query($query); $getid="SELECT id FROM file ORDER BY created DESC LIMIT 1 "; $result2 = $dbLink->query($getid); $mysqli->error; $row1=$result2->fetch_assoc(); // Close the mysql connection $dbLink->close(); }} else {echo 'Error! A file was not sent!';} /////////////////////////Download/////////////////////////////////////////// // Make sure an ID was passed // Get the ID $id= $row1['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("","root","blabla",'blabla'); if(mysqli_connect_errno()) { die("MySQL connection failed: ". mysqli_connect_error()); } // Fetch the file information $query = "SELECT `mime`, `name`, `size`, `data` FROM `file` WHERE `id` = {$id}"; $resultb=$dbLink->query($query); if($resultb) { // Make sure the result is valid if($resultb->num_rows == 1) { $rowb =mysqli_fetch_assoc($resultb); // Print headers header("Content-Type: ".$rowb['mime']); header("Content-Length: ".$rowb['size']); header("Content-Disposition: attachment; filename=".$rowb['name']); // Print data echo $rowb['data']; } else { echo 'Error! No image exists with that ID.'; } // Free the mysqli resources @mysqli_free_result($resultb); } else { echo "Error! Query failed:
"; } @mysqli_close($dbLink); } echo 'end'; echo $rowb['data']; ?>


plz help me…I am so third to this…help me… :-*

Sponsor our Newsletter | Privacy Policy | Terms of Service