saco721 Posted October 17, 2007 Share Posted October 17, 2007 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! Quote Link to comment https://forums.phpfreaks.com/topic/73652-solved-file-empty-when-forcing-saveas/ Share on other sites More sharing options...
BlueSkyIS Posted October 17, 2007 Share Posted October 17, 2007 code please. Quote Link to comment https://forums.phpfreaks.com/topic/73652-solved-file-empty-when-forcing-saveas/#findComment-371563 Share on other sites More sharing options...
saco721 Posted October 17, 2007 Author Share Posted October 17, 2007 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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/73652-solved-file-empty-when-forcing-saveas/#findComment-371754 Share on other sites More sharing options...
BlueSkyIS Posted October 17, 2007 Share Posted October 17, 2007 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']); Quote Link to comment https://forums.phpfreaks.com/topic/73652-solved-file-empty-when-forcing-saveas/#findComment-371762 Share on other sites More sharing options...
saco721 Posted October 17, 2007 Author Share Posted October 17, 2007 Thank you !, I just used the filename instead of the complete path - works fine. best wishes, Saco Quote Link to comment https://forums.phpfreaks.com/topic/73652-solved-file-empty-when-forcing-saveas/#findComment-371820 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.