Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9294267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T21:19:55+00:00 2026-06-18T21:19:55+00:00

I use the following php file to upload data into a local storage and

  • 0

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. i cant use File_get contents method since there may be bigger size data uploaded. What can i do for that?

here is my Uploading code Upload.php

$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->multi_query("call sp_upload_file('".$id."','" . $filename . "','".$path."')");
    if ($result) 
    {
        do {
            if ($temp_resource = $mysqli->use_result()) 
            {
                while ($row = $temp_resource->fetch_array(MYSQLI_ASSOC)) {
                    array_push($rows, $row);
                }
                $temp_resource->free_result();
            }
        } while ($mysqli->next_result());
    }
    echo "Successfully Uploaded";
}
else
{
    echo " Invalid File Type";
}

The Stored Procedure sp_upload_file is as follows.

 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 ;

The following is the code for Downloading the file

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;

}

The following is the sp for downloading data:

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 ;

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T21:19:56+00:00Added an answer on June 18, 2026 at 9:19 pm

    Here is a simple download script. You can use your query to get the full path of the file (or relative). It has its own buffer built in so no need to use ob_start

     if ($fd = fopen ($fullPath, "r")) {
            $fsize = filesize($fullPath);
            $path_parts = pathinfo($fullPath);
    
            header("Content-type: application/octet-stream");
            header("Content-Disposition: attachment; filename=\"".$path_parts["basename"]."\"");
            header("Content-length: $fsize");
            header("Cache-control: private"); //use this to open files directly
            while(!feof($fd)) {
                $buffer = fread($fd, 2048);
                echo $buffer;
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote the following php function to upload files but I'm having a hard
I was following this tutorial . I need to use a php file's ouput
I'm trying use mod_rewrite to rewrite URLs from the following: http://www.site.com/one-two-file.php to http://www.site.com/one/two/file.php The
Hello Sir i want send list of data to php server i use following
I try use string as a regular expression pattern but I've following errors PHP
I'm trying to use the following code to upload a csv file usually around
I currently use the following code to upload one file to a remote server:
I am using cake PHP file upload with the AJAX form submit. But it
I am trying to upload file using dropbox api but following Code shows some
I'm trying to use the following in my routes.php file: Router::connect( /:slug/:controller/:action/:id, array('controller' =>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.