用于下载名称中包含utf-8字符的文件的PHP脚本

Swa*_*oop 2 php download

我有外国字符命名的文件,我使用utf8_encode()编码名称后上传.但是现在,当我尝试使用readfile()下载它们时,它们会给出"未找到"错误.

我已粘贴下面的代码.我认为问题在于我定义的一些标题.谁能告诉我这是什么问题?

<?php

    ini_set('mbstring.internal_encoding','UTF-8');
    ini_set('mbstring.http_input','auto');
    ini_set('mbstring.http_output','UTF-8');
    ini_set('mbstring.detect_order','auto');
    ini_set('default_charset','UTF-8');

    $url = "http://filedownload.s3.amazonaws.com/cénari.txt";
    header('Content-Description: File Transfer');
    header('Content-Type: text/html; charset=UTF-8');
    header('Pragma: public');
    header('Content-Length: ' . filesize($url));
    header('Content-disposition: attachment; filename='.utf8_decode($url));
    ob_clean();
    flush();
    readfile($url);

?>
Run Code Online (Sandbox Code Playgroud)

我还附加了运行此代码时下载的文件.

我使用PHP下载而不是S3中的其他方法因为所有这些文件都是公共的,我隐藏它们的唯一方法就是隐藏网址.

igo*_*orw 6

您可能需要urlencode()名称:

$url = "http://filedownload.s3.amazonaws.com/" . urlencode("cénari.txt");
Run Code Online (Sandbox Code Playgroud)