PHP header() Can not open xlsx file after download -


i use header() download xlsx file given url. file downloaded can't not open it. shows error enter image description here

below code

$url = "http://example.com/attachment/file.xlsx" header("content-type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); header('content-disposition: attachment; filename=test.xlsx'); readfile($url); exit(); 

randy, question looks weird. url in serve response way different 1 in code.

before commencing download - sending headers, is_file() or other check on url , start download if file exists.

i suspect trying fopen on url, not local file , url may either incorrect or on server not allowing fopen on urls.

sample:

  $url = "http://example.com/attachment/file.xlsx";   if (!fopen($url,'r')) exit('file/url not accessible');    else fclose($url);   header('content-type: application/octet-stream');   header("content-transfer-encoding: binary");    header('content-disposition: attachment; filename=test.xlsx');   readfile($url);   exit(); 

Comments

Popular posts from this blog

serialization - Convert Any type in scala to Array[Byte] and back -

matplotlib support failed in PyCharm on OSX -

python - Matplotlib: TypeError: 'AxesSubplot' object is not callable -