Jump to content

[SOLVED] file empty when forcing saveas


saco721

Recommended Posts

Hi,

 

I am trying to force saveas using array for filename.

 

The problem is that when I click saveas or open, the file is empty. The path to the file is fine, and the file is in the correct directory.

 

However, when the filename is hard coded, the file is fine.

 

Any help would be greatly appreciated!

 

Link to comment
https://forums.phpfreaks.com/topic/73652-solved-file-empty-when-forcing-saveas/
Share on other sites

Hi,

 

here is the code I am using:

 

download.php

<?php

$test1 = "/htdocs/songs/" . $keyarray["item_name".$i] . ".mp3";

echo ("<td><a href=\"samofile.php?arg1=$test1\">download</a></td>");

?>

 

samofile.php

<?php

 

//$strFilePath = $_GET['arg1'];//path is correct and file exists, but when opened or saved file is empty

 

//$strFilePath = "getme.mp3";//downloads file fine

 

$strFileSize = filesize($strFilePath);

 

$strFileName = basename($strFilePath);

 

 

 

header("Content-Type: $ContentType");

 

header("Content-Length: $strFileSize");

 

header("Content-Disposition:attachment; filename=$strFileName");

 

 

 

$fp = fopen($strFileName, 'rb');

 

fpassthru($fp);

 

fclose($fp);

 

?>

ah, you're trying to send an entire path in the URL. you should probably just send the file name if anything. personally, i'd store the info in a database and just send the record identifier, but i digress...

 

if you CAN'T remove the path and filename, you might want to use urlencode on $test1 before you put it into the URL, then urldecode on $_GET['arg1'] to get the decoded value on the next page.

 

echo ("<td><a href=\"samofile.php?arg1=".urlencode($test1)."\">download[/url]</td>");

$strFilePath = urldecode($_GET['arg1']);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.