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('測(cè)試圖片.JPG','GBK','utf8')); $file = realpath('temp.jpg'); //要上傳的文件 $fields['f'] = '@'.$file; // 前面加@符表示上傳圖片 $ch =curl_init(); curl_setopt($ch,CURLOPT_URL,'http://localhost/upload.php'); 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 =<<< 'TEXT' 這里是文件內(nèi)容,也可以是圖片二進(jìn)制,圖片需要修改上傳文件類型 TEXT; $varname = 'my';//上傳到$_FILES數(shù)組中的 key $name = '3.txt';//文件名 $type = 'text/plain';//文件類型 $key = "$varname\"; filename=\"$name\r\nContent-Type: $type\r\n"; $fields[$key] = $contents; $ch =curl_init(); curl_setopt($ch,CURLOPT_URL,'http://localhost/upload.php'); 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 images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

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

Hot Article
Grass Wonder Build Guide | Uma Musume Pretty Derby
1 months ago
By Jack chen
Roblox: 99 Nights In The Forest - All Badges And How To Unlock Them
4 weeks ago
By DDD
Uma Musume Pretty Derby Banner Schedule (July 2025)
1 months ago
By Jack chen
RimWorld Odyssey Temperature Guide for Ships and Gravtech
3 weeks ago
By Jack chen
Windows Security is blank or not showing options
1 months ago
By 下次還敢

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)