Php 如何使用PUT in curl方法将文件上载到服务器
我使用curlput在站点上传文件,但无法理解wy不起作用Php 如何使用PUT in curl方法将文件上载到服务器,php,curl,Php,Curl,我使用curlput在站点上传文件,但无法理解wy不起作用 $url = "http://test.ru"; $localfile = "uploadTest.txt"; $fp = fopen ($localfile, "r"); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_PUT, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1)
$url = "http://test.ru";
$localfile = "uploadTest.txt";
$fp = fopen ($localfile, "r");
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_PUT, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_INFILE, $fp);
curl_setopt($ch, CURLOPT_INFILESIZE, filesize($localfile));
$http_result = curl_exec($ch);
$error = curl_error($ch);
$http_code = curl_getinfo($ch ,CURLINFO_HTTP_CODE);
curl_close($ch);
fclose($fp);
print $http_code;
print "<br /><br />$http_result";
if ($error) {
print "<br /><br />$error";
}
$url=”http://test.ru";
$localfile=“uploadTest.txt”;
$fp=fopen($localfile,“r”);
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,$URL);
curl_setopt($ch,CURLOPT_PUT,1);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
卷曲设置($ch,卷曲填充,$fp);
curl_setopt($ch,CURLOPT_infiresize,filesize($localfile));
$http\u result=curl\u exec($ch);
$error=curl\u error($ch);
$http\u code=curl\u getinfo($ch,CURLINFO\u http\u code);
卷曲关闭($ch);
fclose($fp);
打印$http_代码;
打印“
$http\u结果”;
如果($error){
打印“
$error”;
}
它给出了403错误。我试图在apache.conf中注册一种方法
<Directory />
Options FollowSymLinks
AllowOverride None
Order Deny,Allow
Deny from all
</Directory>
<Directory "%ssitedir%/*">
AllowOverride All
Options -MultiViews +Indexes +FollowSymLinks +IncludesNoExec +Includes +ExecCGI
<LimitExcept GET POST PUT HEAD>
Order deny,allow
Deny from all
</LimitExcept>
</Directory>
<Directory "%sprogdir%/modules/system/html/openserver">
AllowOverride None
Options -MultiViews -Indexes -FollowSymLinks -IncludesNoExec -Includes -ExecCGI
Order deny,allow
Deny from all
Allow from 127.0.0.0/8 ::1/128
Allow from %ips%
%allow%Allow from all
<LimitExcept GET POST PUT HEAD>
Order deny,allow
Deny from all
</LimitExcept>
AddDefaultCharset Off
<IfModule dir_module>
DirectoryIndex index.php
</IfModule>
</Directory>
<Directory "%sprogdir%/modules/system/html/default">
AllowOverride None
Options -MultiViews -Indexes -FollowSymLinks -IncludesNoExec -Includes -ExecCGI
Order deny,allow
Allow from all
<LimitExcept GET POST PUT HEAD>
Order deny,allow
Deny from all
</LimitExcept>
AddDefaultCharset Off
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
</Directory>
<Directory "/cgi-bin">
AllowOverride None
Options None
Order allow,deny
Allow from all
</Directory>
<FilesMatch "^\.ht">
Require all denied
</FilesMatch>
<IfModule alias_module>
Alias /openserver/ "%sprogdir%/modules/system/html/openserver/"
</IfModule>
选项如下符号链接
不允许超限
命令拒绝,允许
全盘否定
允许超越所有
选项-多视图+索引+FollowSymLinks+IncludesNoExec+Includes+ExecCGI
命令拒绝,允许
全盘否定
不允许超限
选项-多视图-索引-FollowSymLinks-IncludesNoExec-Includes-ExecCGI
命令拒绝,允许
全盘否定
允许从127.0.0.0/8::1/128开始
允许来自%ips%
%允许%允许来自所有
命令拒绝,允许
全盘否定
添加默认字符集
DirectoryIndex.php
不允许超限
选项-多视图-索引-FollowSymLinks-IncludesNoExec-Includes-ExecCGI
命令拒绝,允许
通融
命令拒绝,允许
全盘否定
添加默认字符集
DirectoryIndex.html
不允许超限
选项无
命令允许,拒绝
通融
要求全部拒绝
别名/openserver/%sprogdir%/modules/system/html/openserver/“
但它给出了第405个错误
哪里可能有错误?注意:以下两个示例都来自:
Note: both the following examples are from:
http://blog.derakkilgo.com/2009/06/07/send-a-file-via-post-with-curl-and-php/
example 1:
$file_name_with_full_path = realpath('./sample.jpeg');
$post = array('extra_info' => '123456','file_contents'=>'@'.$file_name_with_full_path);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$target_url);
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$result=curl_exec ($ch);
curl_close ($ch);
example 2:
<?php
$target_url = 'http://127.0.0.1/accept.php';
//This needs to be the full path to the file you want to send.
$file_name_with_full_path = realpath('./sample.jpeg');
/* curl will accept an array here too.
* Many examples I found showed a url-encoded string instead.
* Take note that the 'key' in the array will be the key that shows up in the
* $_FILES array of the accept script. and the at sign '@' is required before the
* file name.
*/
$post = array('extra_info' => '123456','file_contents'=>'@'.$file_name_with_full_path);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$target_url);
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
$result=curl_exec ($ch);
curl_close ($ch);
echo $result;
?>
http://blog.derakkilgo.com/2009/06/07/send-a-file-via-post-with-curl-and-php/
例1:
$file_name_,路径为realpath('./sample.jpeg');
$post=array('extra_info'=>'123456','file_contents'=>'@.$file_name_与_full_路径);
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,$target_URL);
卷曲设置($ch,卷曲设置桩,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$post);
$result=curl\u exec($ch);
卷曲关闭($ch);
例2: