By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,414 Members | 1,050 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,414 IT Pros & Developers. It's quick & easy.

Problem with force download while downloading a 2-byte char filename using php

P: 1

I'm unable to download a file that is having a 2-byte char in its name (e.g.テ) using force download option. Though, am able to download file names involving ASCII chars. I have tried URL encoding too, but with no success.

Can someone provide details on how to handle the 2-byte char URLs and download the files?

Appreciate your suggestions/help in resolving it.

Here is my code:

function readfile_chunked($filename,$retbytes=true)
$chunksize = 1*(1024*1024); // how many bytes per chunk
$buffer = '';
$cnt =0;
$handle = fopen($filename, 'rb');
if ($handle === false)
return false;
while (!feof($handle))
//read a chunk
$buffer = fread($handle, $chunksize);
//send the chunk
echo $buffer;
//flush the chunk
//increment the size read/sent
if ($retbytes)
$cnt += strlen($buffer);
//close file
$status = fclose($handle);
if ($retbytes && $status)
return $cnt; // return num. bytes delivered like readfile() does.
return $status;

$filename = $_GET['file'];
echo "ERROR: No filename specified. Please try again.";
// fix for IE caching or PHP bug issue
header("Pragma: public");
header("Expires: 0"); // set expiration time
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
// browser must download file from server instead of cache
// force download dialog
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");

// use the Content-Disposition header to supply a recommended filename and
// force the browser to display the save dialog.
header("Content-Disposition: attachment; filename=" . basename($filename) . ";");
header("Content-Transfer-Encoding: binary");

header("Content-Length: " . filesize($filename));

readfile_chunked(urldecode($filename), false);



Sep 13 '06 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.