<?php
href="downfile.php?path=xxx"
===============
downfile.php
// We'll be outputting a flash
header('Content-type: application/x-shockwave-flash');
// It will be called downloaded.swf
Header("Content-Disposition: attachment; filename=".basename($path));
// The PDF source is in original.swf
readfile($path);
?>
在實現過程中,遇到的問題是保存完文件之後,打開沒有內容,都是一片空白。後來發現是文件類型,以及readfile()函數的問題。
首先要注意到的是,在header 中給出文件類型。
Content-Type:
它定義了數據的類型,以便數據能被適當的處理。有效的類型有:text,image,audio,video,
applications,multipart和message。注意任何一個二進制附件都應該被叫做application/octet-
stream。這個頭的一些用例爲:image/jpg, application/mswork,multipart/mixed,這只是很少的
一部分。 例中application/x-shockwave-flash爲flash格式。
另外需要注意的一點是,readfile()函數要給出完整的鏈接。即是絕對鏈接。剛開始沒有讀到文件,主要是使用了相對鏈接的關係。