Reputation: 5522
I am using cURL to firstly get a list of files from a remote FTP server. I then use the same Curl Handle to download that file. After the download, I then once again use the same handle to remove the file.
When I use the following code to remove the file, it does succeed:
curl_setopt($tmp["curl"], CURLOPT_QUOTE, array("DELE " . $tmp["file"]));
although I get the following in the logs:
[PHP Warning] curl_exec(): CURLOPT_FILE resource has gone away, resetting to default [l:52]
The reason is that when I first downloaded the file, I set the following option:
curl_setopt($tmp["curl"], CURLOPT_FILE, $tmp["file_handle"]);
My question is, how do I unset options that I have added? I want to remove the above option so that I can reuse the curl connection to delete the file.. or what option to I set to basically unset this option?
Upvotes: 6
Views: 9209
Reputation: 31
I wanted to use the same curl instance to save to a file, then request a page and save to a variable.
After trying all of the above and other suggestions, none of which worked, I came accross the correct solution....
reset file to default STDOUT
curl_setopt($ch, CURLOPT_FILE, fopen('php://stdout','w'));
dont' forget to re-enable return transfer if that's what you want to do
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
Upvotes: 3
Reputation: 167
If you look at this post, as well, basically reset the CURLOPT_FILE option to the default STDOUT (NULL will cause a warning!).
Then, if you mean to capture the output to a string, you need to explicitly set the CURLOPT_RETURNTRANSFER option to true to override the file option, even if you set it earlier on.
Hope this helps somebody who was also looking for this answer.
Upvotes: 1
Reputation: 496
just setting it to NULL
should work
curl_setopt($tmp["curl"], CURLOPT_FILE, NULL);
as discussed here
http://curl.haxx.se/mail/lib-2012-03/0082.html
Upvotes: 1
Reputation: 5351
You unset an option by setting the value to null
, like so:
curl_setopt($tmp["curl"], CURLOPT_QUOTE, null);
Upvotes: 5