dongshu9458 2012-10-02 17:11
浏览 10

js使用xmlhttp访问非公共文件

To access files outside the public webspace you need a script in the public webspace that can fetch the contents from the private folder, e.g.

$allowedFiles = array(
    1 => '/path/to/private/space/on/server/file1.txt',
    2 => '/path/to/private/space/on/server/file2.txt',
    3 => '/path/to/private/space/on/server/file3.txt',
    4 => '/path/to/private/space/on/server/file4.txt',
);

$id = filter_var($_GET['id'], FILTER_VALIDATE_INT);

if (isset($allowedFiles[$id])) {
    readfile($allowedFiles[$id]);
}

Now when you do

xmlhttp.open("GET","file.php?id=4",false); <==Notice last parameter is false (sync) the script will send the content of

/path/to/private/space/on/server/file4.txt to the client.

This piece of code work for small files, but when the file es bigger, i.e. 5 mgbytes, this code fails.

Any Idea?

  • 写回答

1条回答 默认 最新

  • duanchi5078 2012-10-02 17:22
    关注

    Check your php.ini and try modifying the upload_max_filesize and post_max_size value to an higher value.

    Put all the files you want to have forced downloaded in a directory, and set this in your .htaccess for that directory.

    <Files *.*>
    ForceType applicaton/octet-stream
    </Files>
    

    Found in this thread : http://www.sitepoint.com/forums/showthread.php?700250-PHP-File-%28Size%29-Download-Limit There are some other solutions.

    评论

报告相同问题?

悬赏问题

  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线