2012-10-19 3 views
0

xyz abc.csv과 같은 이름의 space과 함께 CSV 파일이있을 때마다 PHP 코드를 통해 다운로드 할 수있는 문제가 발생하고 다른 CSV는 공백이 없으며 제대로 작동하고 제대로 다운로드됩니다.CSV 다운로드 PHP 공간 문제

다음은 내 다운로드 코드 :

파일 다운로드를 얻을 수
$file_path = 'http://www.servername.com/subfolder/subfolder/'; 
$file = urlencode('Today new_18-10-2012_21-13-21.csv'); 

header('Content-Type: application/csv'); 
header('Content-Disposition: attachment; filename="'.$file.'"'); 
header('Pragma: no-cache'); 
readfile($file_path.$file); 

, 그 항상 0 bytes 원본 파일이

이 문제에 대한 어떤 제안 크기

에서 93kb된다.

미리 감사드립니다.

답변

0

대신 urlencoderawurlencode를 사용할 필요가 ... 이것보십시오.

$file_path = 'http://www.servername.com/subfolder/subfolder/'; 

//just filename, no need to save file with url encoded name! 
$file = 'Today new_18-10-2012_21-13-21.csv'; 

header('Content-Type: application/csv'); 
header('Content-Disposition: attachment; filename="' . $file . '"'); 
header('Pragma: no-cache'); 

//here comes url encoding 
readfile($file_path . rawurlencode($file)); 

나를 위해 잘 작동 그것 ... 함수 savedata1를 어떻게해야 무엇

0

이 코드를 사용하십시오. 그것은 당신에게 도움이 될 수 있습니다. 하지만 중요한 것은 간격입니다.

$Filename = 'Today new_18-10-2012_21-13-21.csv'; 
$path = "http://www.servername.com/subfolder/subfolder/"; 
$file = $path.$filename; 
header("Cache-Control: public"); 
header("Content-Description: File Transfer"); 
header("Content-Disposition: attachment; filename=$filename"); 
header("Content-Type: application/csv"); 
header("Content-Transfer-Encoding: binary"); 
readfile($file); 
+0

? 콘텐츠 유형이 잘못되었습니다. 무엇이 당신의 코드를 개선합니까? – m4t1t0

+0

savedata1의 필요가 없습니다. 데이터를 데이터베이스에 저장하는 기능입니다. – Prem