PHP- File Upload and download without using file_get_contents
<p>I use the following php file to upload data into a local storage and store the path in the db.
The files are getting uploaded.But when i try to download it i am not getting the content of the file. I get only blank page. <strong>i cant use File_get contents method since there may be bigger size data uploaded.</strong> What can i do for that?</p>

<p>here is my Uploading code Upload.php</p>

<pre><code>$id=$_POST['id'];
$fileTypes = array('txt','doc','docx','ppt','pptx','pdf');
$fileParts = pathinfo($_FILES['uploaded_file']['name']);
if(in_array($fileParts['extension'],$fileTypes))
{
    $filename = $_FILES["uploaded_file"]["name"];
    $location = "D:\\Uploads/";
    $path = $location . basename( $_FILES['uploaded_file']['name']); 
    move_uploaded_file( $_FILES["uploaded_file"]["tmp_name"], $location . $_FILES['uploaded_file']['name']);
    $result = $mysqli-&gt;multi_query("call sp_upload_file('".$id."','" . $filename . "','".$path."')");
    if ($result) 
    {
        do {
            if ($temp_resource = $mysqli-&gt;use_result()) 
            {
                while ($row = $temp_resource-&gt;fetch_array(MYSQLI_ASSOC)) {
                    array_push($rows, $row);
                }
                $temp_resource-&gt;free_result();
            }
        } while ($mysqli-&gt;next_result());
    }
    echo "Successfully Uploaded";
}
else
{
    echo " Invalid File Type";
}
</code></pre>

<p>The Stored Procedure sp_upload_file is as follows.</p>

<pre><code> DELIMITER $$

USE `test`$$

DROP PROCEDURE IF EXISTS `sp_upload_file`$$

CREATE PROCEDURE `sp_upload_file`(IN id INT,IN filename VARCHAR(200),IN path VARCHAR(200))
BEGIN
IF EXISTS(SELECT `Training_Id`, `Material_Name`,Material_Path FROM `training_material` WHERE `Training_Id` = id AND `Material_Name` = filename AND `Material_Path` = path )
THEN

 UPDATE 
    `training_material` 
 SET 
    Training_Id =  id,
    Material_Name = filename,

    Material_Path = path,
    Modified_Date = NOW()
WHERE 
    `Training_Id` = id AND 
    `Material_Name` = filename AND 
    `Material_Path` = path ;
 ELSE
 INSERT INTO 
 `training_material`
    (`Training_Id`,
    `Material_Name`,
    `Material_Path`,

    `Created_Date`,
    `Modified_Date`)
 VALUES 
    (id,
    filename,
    path,

    NOW()
    ,NOW());
END IF;
END$$

DELIMITER ;
</code></pre>

<p>The following is the code for Downloading the file</p>

<pre><code>if(isset($_GET['id']))
{
$id=$_GET['id'];
$mid=$_GET['mid'];
$query = "call sp_download_file('".$mid."')";
$result = mysql_query($query) or die('Error, query failed');
list($name) = mysql_fetch_array($result);
header("Content-Disposition: attachment; filename=$name");
ob_clean();
flush();

exit;
</code></pre>

<p>}</p>

<p>The following is the sp for downloading data:</p>

<pre><code>DELIMITER $$

USE `test`$$

DROP PROCEDURE IF EXISTS `sp_download_file`$$

CREATE DEFINER=`root`@`%` PROCEDURE `sp_download_file`(IN id INT)
BEGIN
 SELECT Material_Name FROM training_material WHERE `Training_Material_Id` = id;

END$$

DELIMITER ;
</code></pre>

<p>please help in this.I know i need to change in download.php file.But dont know what changes i need to make.</p>
