PHP Curl下载文件名为

PHP Curl下载文件名为,php,curl,Php,Curl,我有一个Curl下载文件,但问题是,我需要输出文件名为的文件,其中输出: 例如: $result = false; $path = "http://mywebsite.com/download.php?file=123"; set_time_limit(0); //prevent timeout $ch2=curl_init(); $file = fopen('upload/'.$name,'w+'); curl_seto

我有一个Curl下载文件,但问题是,我需要输出文件名为的文件,其中输出:

例如:

$result = false;
     $path = "http://mywebsite.com/download.php?file=123";
        set_time_limit(0); //prevent timeout
        $ch2=curl_init();
        $file = fopen('upload/'.$name,'w+');
        curl_setopt($ch2, CURLOPT_URL, $url);
        curl_setopt($ch2, CURLOPT_FILE, $file); //auto write to file
        curl_setopt($ch2, CURLOPT_TIMEOUT, 5040);
        curl_setopt($ch2, CURLOPT_POST, 1);
        curl_setopt($ch2, CURLOPT_SSL_VERIFYHOST, 1);
        curl_setopt($ch2, CURLOPT_SSL_VERIFYPEER, FALSE); 
        curl_setopt($ch2, CURLOPT_SSLVERSION, 3); 
        curl_setopt($ch2, CURLOPT_FOLLOWLOCATION, true);
        curl_exec($ch2);    
        curl_close($ch2);
        fclose($file);
在我的示例中,我需要下载文件的名称是$name=(文件名)

比如,如果我下载文件,我可以返回自定义的\u name\u file.zip

但是我需要写入文件将这个自定义文件的名称


有什么想法吗

不能这样做,因为只有在开始下载并获取http头并提取内容处置内容后,名称才可用。您最好将其写入一个临时文件,然后重命名/移动该临时文件。hu,我可以在tmp文件中输出文件并更改名称,但是,在这种方法中,我不能同时获取头文件?我们需要2个卷发才能得到文件名?0.o“curl具有愚蠢的头处理,但您可以仅使用一个请求检索头: