国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Home php教程 PHP源碼 php curl upload file

php curl upload file

Nov 08, 2016 pm 02:23 PM

Assume that the server-side upload file processing script upload.php:

<?php
 
print_r($_POST);
print_r($_FILES);
?>

1. Use the CURL default method



//如果php文件是utf8編碼,系統(tǒng)是GBK編碼,那么就需要轉(zhuǎn)下編碼,要不然Php在系統(tǒng)中找不到這個(gè)文件 
$file = realpath(mb_convert_encoding(&#39;測(cè)試圖片.JPG&#39;,&#39;GBK&#39;,&#39;utf8&#39;));
 
$file = realpath(&#39;temp.jpg&#39;); //要上傳的文件 
$fields[&#39;f&#39;] = &#39;@&#39;.$file; // 前面加@符表示上傳圖片
 
$ch =curl_init();
 
 
curl_setopt($ch,CURLOPT_URL,&#39;http://localhost/upload.php&#39;);
 
curl_setopt($ch,CURLOPT_POST,true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
 
 
$content = curl_exec($ch);
 
echo $content;

2. An alternative approach, sometimes we need to treat dynamically generated content as a file Upload to a remote server but don't want to build temporary files in the local server. This way we have this alternative way of writing

$contents =<<< &#39;TEXT&#39;
這里是文件內(nèi)容,也可以是圖片二進(jìn)制,圖片需要修改上傳文件類型
TEXT;
 
$varname = &#39;my&#39;;//上傳到$_FILES數(shù)組中的 key
$name = &#39;3.txt&#39;;//文件名
$type = &#39;text/plain&#39;;//文件類型
 
$key = "$varname\"; filename=\"$name\r\nContent-Type: $type\r\n";
$fields[$key] = $contents;
 
 
 
$ch =curl_init();
 
 
curl_setopt($ch,CURLOPT_URL,&#39;http://localhost/upload.php&#39;);
 
curl_setopt($ch,CURLOPT_POST,true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
 
 
$content = curl_exec($ch);
 
echo $content;

Statement of this Website
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

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

PHP Tutorial
1502
276