[实践OK]用 curl上传文件,Linux的Shell下用CURL上传文件实例于php://input的接收,PHP扩展用Curl上传文件。
上传文件的curl参数是-T:
1)上传uploadContents.txt文件内容:
this is upload file by php.
2)接收代码:
来自plupload里通过swf一个文件小于自己配置的10M时就一次性上传的协议,Flash是这样进行提交的:
Content-Disposition: form-data; name="name" p18e57aitdkecp1vbe40lccu4.zip
XXXXXXXXXX 文件内容
3)运行打印:
C:\Users\admin>curl -d"dfd=php://input can not read here's contents" -T"D:\uploadContents.txt" http://localhost/php_input.php
this is upload file by php.
4)说明,对于-d参数,其PHP的php://input是不会接收的,其接收的是二进制流,用$_POST,是可以打印出来的(但通过linux下的shell同时发送-d -T是只能打出-T内容)。
如,通过给PHP里的php://input上传一个文件,发现这个文件不能被读取到,说明它就是只能接二进制文件的,如下:
C:\Users\admin>curl -F upload_file=@D:\uploadContents.txt -F "name=yangqi" http://localhost/php_input.php
-F/--form <name=content> Specify HTTP multipart POST data (H)
--form-string <name=string> Specify HTTP multipart POST data (H)
Array
(
[upload_file] => Array
(
[name] => uploadContents.txt
[type] => text/plain
[tmp_name] => D:\wamp\tmp\phpDAB9.tmp
[error] => 0
[size] => 76
)
)
Array
(
[name] => yangqi
)
接收代码如下:
_______________________分块传时是这样的_______________________________
Content-Disposition: form-data; name="name" p18e57g55eof2u6k19971jo1cvu8.zip
Content-Disposition: form-data; name="chunk" 0
Content-Disposition: form-data; name="chunks" 5
上传文件内容XXXX
______________________________________________________________________________________
更多参考如下Url:http://jackxiang.com/post/6421/
curl -F userfile=@/usr/local/apache2/conf/httpd.conf http://app.space.sina.com.cn/upload.php // 上传
curl -d "get=123&post=222" http://app.space.sina.com.cn/get_post.php //post
curl http://app.space.sina.com.cn/get_post.php?"post=888&get=1212" //引号引起来get
加上访问时间(注意:这儿的upload_file相当于控件html file的name):
curl -s -w '%{time_connect}:%{time_starttransfer}:%{time_total}' -F upload_file=@/home/xiangdong/uploadFileTest/buer.rmvb "http://up.xiyou.cntv.cn/uptest.php"
0.001:0.001:14.458
PHP扩展用Curl上传文件:
调用的实际上传:
附录Flash进行多文件上传时的代码,在单文件时是通过php:input,而多文件时是_FILES进行分块上传的,upload.php里的代码如下:
来自:http://www.oschina.net/code/snippet_12_5808
1)上传uploadContents.txt文件内容:
this is upload file by php.
2)接收代码:
来自plupload里通过swf一个文件小于自己配置的10M时就一次性上传的协议,Flash是这样进行提交的:
Content-Disposition: form-data; name="name" p18e57aitdkecp1vbe40lccu4.zip
XXXXXXXXXX 文件内容
3)运行打印:
C:\Users\admin>curl -d"dfd=php://input can not read here's contents" -T"D:\uploadContents.txt" http://localhost/php_input.php
this is upload file by php.
4)说明,对于-d参数,其PHP的php://input是不会接收的,其接收的是二进制流,用$_POST,是可以打印出来的(但通过linux下的shell同时发送-d -T是只能打出-T内容)。
如,通过给PHP里的php://input上传一个文件,发现这个文件不能被读取到,说明它就是只能接二进制文件的,如下:
C:\Users\admin>curl -F upload_file=@D:\uploadContents.txt -F "name=yangqi" http://localhost/php_input.php
-F/--form <name=content> Specify HTTP multipart POST data (H)
--form-string <name=string> Specify HTTP multipart POST data (H)
Array
(
[upload_file] => Array
(
[name] => uploadContents.txt
[type] => text/plain
[tmp_name] => D:\wamp\tmp\phpDAB9.tmp
[error] => 0
[size] => 76
)
)
Array
(
[name] => yangqi
)
接收代码如下:
_______________________分块传时是这样的_______________________________
Content-Disposition: form-data; name="name" p18e57g55eof2u6k19971jo1cvu8.zip
Content-Disposition: form-data; name="chunk" 0
Content-Disposition: form-data; name="chunks" 5
上传文件内容XXXX
______________________________________________________________________________________
更多参考如下Url:http://jackxiang.com/post/6421/
curl -F userfile=@/usr/local/apache2/conf/httpd.conf http://app.space.sina.com.cn/upload.php // 上传
curl -d "get=123&post=222" http://app.space.sina.com.cn/get_post.php //post
curl http://app.space.sina.com.cn/get_post.php?"post=888&get=1212" //引号引起来get
加上访问时间(注意:这儿的upload_file相当于控件html file的name):
curl -s -w '%{time_connect}:%{time_starttransfer}:%{time_total}' -F upload_file=@/home/xiangdong/uploadFileTest/buer.rmvb "http://up.xiyou.cntv.cn/uptest.php"
0.001:0.001:14.458
<?php
$uploaddir = '/home/xiangdong2/pic_all_here';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile))
{
echo "File is valid, and was successfully uploaded.\n";
} else {
echo "Possible file upload attack!\n";
echo 'Here is some more debugging info:';
print_r($_FILES);
}
?>
$uploaddir = '/home/xiangdong2/pic_all_here';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile))
{
echo "File is valid, and was successfully uploaded.\n";
} else {
echo "Possible file upload attack!\n";
echo 'Here is some more debugging info:';
print_r($_FILES);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>upload file</title>
</head>
<body>
<form id="form1" name="form1" enctype="multipart/form-data" method="post" action="http://app.space.sina.com.cn/upload.php">
<label>
<input type="file" name="userfile" id="fileField" />
</label>
<label>
<input type="submit" name="button" id="button" value="upload" />
</label>
</form>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>upload file</title>
</head>
<body>
<form id="form1" name="form1" enctype="multipart/form-data" method="post" action="http://app.space.sina.com.cn/upload.php">
<label>
<input type="file" name="userfile" id="fileField" />
</label>
<label>
<input type="submit" name="button" id="button" value="upload" />
</label>
</form>
</body>
</html>
<?php
if(isset($_REQUEST['get']))
{
$get =$_REQUEST['get'];
}else{
$get="get";
}
if(isset($_REQUEST['post']))
{
$post =$_REQUEST['post'];
}else{
$post="post";
}
echo "get=".$get."\n";
echo "post=".$post."\n";
?>
if(isset($_REQUEST['get']))
{
$get =$_REQUEST['get'];
}else{
$get="get";
}
if(isset($_REQUEST['post']))
{
$post =$_REQUEST['post'];
}else{
$post="post";
}
echo "get=".$get."\n";
echo "post=".$post."\n";
?>
PHP扩展用Curl上传文件:
调用的实际上传:
附录Flash进行多文件上传时的代码,在单文件时是通过php:input,而多文件时是_FILES进行分块上传的,upload.php里的代码如下:
来自:http://www.oschina.net/code/snippet_12_5808
作者:jackxiang@向东博客 专注WEB应用 构架之美 --- 构架之美,在于尽态极妍 | 应用之美,在于药到病除
地址:https://jackxiang.com/post/1260/
版权所有。转载时必须以链接形式注明作者和原始出处及本声明!
最后编辑: jackxiang 编辑于2015-3-30 09:27
评论列表