English 中文(简体)
PHP 下载CURL
原标题:PHP Downloading with CURL

我的问题正在引起我的cra。

我正试图通过一个参数从一个遥远的服务器下载一个文件,该参数是从外部来源寄给我,并将它节省到我的服务器上的一个特定目录。

该守则是:

// value of this variable is something like http://api.com/20110720-202122_dceb89c3-a468-4de8-a37f-4f594bc5aab8.mp3

$recordingURL = $_REQUEST[ RecordingURL ];

$filename = basename($recordingURL);

$path =  ../mp3/TT/ .$filename;
if(!file_exists($path))
{    
if (!mkdir($path, 0755 , true)) 
    {   
    errorLog( handlemp3.php , 0 , could not make recording directory ); 
    }
}

$fp = fopen($path,  w );
$ch = curl_init($recordingURL);
curl_setopt($ch, CURLOPT_FILE, $fp);
$data = curl_exec($ch);
curl_close($ch);
fclose($fp);

At first I was seeing that the "TT" directory was not being created and I realized that the problem was that I did not set the recursive property in the mkdir to true. Once I did that, I saw the TT directory created on the server. The weird thing is that now I am not seeing the MP# created on the server.

没有人会想为什么? 我没有“美元=错误_get_last()”,并且看到,我正在经历一个错误,如“Directive Register_long_arrays在PHP5.3和更大的范围内被折旧”,但我没有想法可以推翻这一错误。

谁能在这里帮助?

感谢!

问题回答

Try this:

file_put_contents( /path/to/local/file , file_get_contents( http://site.com/remote/file ));

我确信,这是正确的:

curl_setopt($ch, CURLOPT_FILE, $fp);

如果我错了,但我认为你已上载了<代码>(fp)的内容,而不是下载<代码>$fp的内容。

Remove the following lines:

$fp = fopen($path,  w );
curl_setopt($ch, CURLOPT_FILE, $fp);
fclose($fp);

并将之置于末尾(见curl_close):

file_put_contents($path, $data);

和一位主人一样,这是我做的错误: (1) 作为一种扼杀而不是ger2而通过许可,将档案名称列入掩体内,因此档案名称在夹中,但被定为第3号目录,没有将档案名称列入露天。





相关问题
How to upload and download file from a server using C#

I am developing a webpage in that the user can download their Resume for Edit. So I have a link to download the article. I use the following code for download. DataTable dt = user.getUserDetails(2); ...

Detecting PDF Download

I have recently added functionality for generating pdf reports to a web application. However the reports can be quite large and take some time to show the pdf download dialog. I want to show a spinner ...

Writing file to users giving sporadic error in IE

I have a very interesting issue with only specific IE implementations. I have an ASPX page that is used to write files down to the user, as part of the process the page uses the following code to ...

PHP - List of Excel files to download from Intranet Site?

I have a intranet site running PHP 5 that needs to list a folder containing only Excel files. Ideally the user needs to be able to input some search criteria (ie date) and the files would be filtered ...

Determine total size of SVN directory/trunk

Is there a way to count/calculate the total size of a svn directory if you were to checkout a revision? I have limited internet downloads so I need to know how big something is before I go and ...

Scala and html: download an image (*.jpg, etc) to Hard drive

I ve got a Scala program that downloads and parses html. I got the links to the image files form the html, Now I need to transfer those images to my hard drive. I m wondering what the best Scala ...

Downloading file with wxHTTP?

Im really stumped. Im using the wxHTTP class in wxWidgets to try and download two files. The first request succeeds but the second one fails when wxHTTP->GetInputStream is called. Between downloads, ...

热门标签