Heim >Backend-Entwicklung >PHP-Tutorial >php curl上传文件的简单例子

php curl上传文件的简单例子

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-25 08:58:081273Durchsuche
本文介绍下,在php中用curl上传文件一个小例子,有需要的朋友,参考下吧。

在php中上传文件,可以用常规的表单提交方式,也可以使用curl。

这里介绍一个php curl方式上传文件的例子:

<?php
    $file = array("upimg"=>"@E:/png.png");//文件路径,前面要加@,表明是文件上传.
    $curl = curl_init("http://localhost/a.php");
    curl_setopt($curl,CURLOPT_POST,true);
    curl_setopt($curl,CURLOPT_POSTFIELDS,$file);
    curl_exec($curl);
//by bbs.it-home.org
?>

说明: curl方式上传文件,无需创建任何表单,代码更简洁。



Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn