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
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);

 

?>

Link to comment
Share on other sites

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']);

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.