Home >Backend Development >PHP Tutorial >What should you pay attention to when uploading php files?

What should you pay attention to when uploading php files?

小云云
小云云Original
2018-02-27 09:34:291765browse

This article mainly shares with you what you need to pay attention to when uploading PHP files. I hope it can help you.

php version difference:

<=5.4 curl上传文件只支持@语法= 5.5 支持@语法和CURLFile类大于=5.6 只支持CURLFile类

// Compatibility writing reference example

$curl = curl_init();if (class_exists(&#39;\CURLFile&#39;)) {// 这里用特性检测判断php版本
     curl_setopt($curl, CURLOPT_SAFE_UPLOAD, true);        $data = array(&#39;file&#39; => new \CURLFile(realpath($source)));//>=5.5
 } else {     if (defined(&#39;CURLOPT_SAFE_UPLOAD&#39;)) {
         curl_setopt($curl, CURLOPT_SAFE_UPLOAD, false);
     }     $data = array(&#39;file&#39; => &#39;@&#39; . realpath($source));//<=5.5
 }

 curl_setopt($curl, CURLOPT_URL, $url);
 curl_setopt($curl, CURLOPT_POST, 1 );
 curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
 curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
 curl_setopt($curl, CURLOPT_USERAGENT,"TEST"); $result = curl_exec($curl); $error = curl_error($curl);

         

php version difference:

<=5.4 curl上传文件只支持@语法= 5.5 支持@语法和CURLFile类大于=5.6 只支持CURLFile类

// Compatibility writing reference example

$curl = curl_init();if (class_exists(&#39;\CURLFile&#39;)) {// 这里用特性检测判断php版本
     curl_setopt($curl, CURLOPT_SAFE_UPLOAD, true);        $data = array(&#39;file&#39; => new \CURLFile(realpath($source)));//>=5.5
 } else {     if (defined(&#39;CURLOPT_SAFE_UPLOAD&#39;)) {
         curl_setopt($curl, CURLOPT_SAFE_UPLOAD, false);
     }     $data = array(&#39;file&#39; => &#39;@&#39; . realpath($source));//<=5.5
 }

 curl_setopt($curl, CURLOPT_URL, $url);
 curl_setopt($curl, CURLOPT_POST, 1 );
 curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
 curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
 curl_setopt($curl, CURLOPT_USERAGENT,"TEST"); $result = curl_exec($curl); $error = curl_error($curl);

Related recommendations:

php file upload class and PHP encapsulated multi-file upload class sharing

one PHP file upload class sharing_php example

PHP file upload analysis

The above is the detailed content of What should you pay attention to when uploading php files?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn