gpt4 book ai didi

来自文件路径的 PHP CURL PUT

转载 作者:可可西里 更新时间:2023-11-01 00:03:39 27 4
gpt4 key购买 nike

我正在尝试对文件执行 CURL PUT,但我遇到了问题。

这是我的代码:

$url_path_str = 'http://my_url';
$file_path_str = '/my_file_path';

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, ''.$url_path_str.'');
curl_setopt($ch, CURLOPT_PUT, 1);

$fh_res = fopen($file_path_str, 'r');
$file_data_str = fread($fh_res, filesize($file_path_str));

curl_setopt($ch, CURLOPT_INFILE, $fh_res);
curl_setopt($ch, CURLOPT_INFILESIZE, filesize($file_path_str));
fclose($fh_res);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$curl_response_res = curl_exec ($ch);

脚本一直超时,我不确定为什么。

我会很感激一些帮助。谢谢。

最佳答案

我想通了。恰好是 fclose 导致了这个问题。我只是把它放在 curl_exec 之后。

修改后的代码:

$url_path_str = 'http://my_url';
$file_path_str = '/my_file_path';

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, ''.$url_path_str.'');
curl_setopt($ch, CURLOPT_PUT, 1);

$fh_res = fopen($file_path_str, 'r');

curl_setopt($ch, CURLOPT_INFILE, $fh_res);
curl_setopt($ch, CURLOPT_INFILESIZE, filesize($file_path_str));

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$curl_response_res = curl_exec ($ch);
fclose($fh_res);

希望这对以后的其他人有帮助。

干杯。

关于来自文件路径的 PHP CURL PUT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7340809/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com