


How Can I Transfer Uploaded Files to Another Server Using cURL in PHP?
Dec 14, 2024 am 01:59 AMTransferring Uploaded Files Using cURL in PHP
You have a web form with a file upload button and an accompanying PHP script that processes the uploaded file. However, you now need to forward the file to another server. This article provides a solution to accomplish this task.
To upload the file, you can utilize cURL with the following steps:
<?php if (function_exists('curl_file_create')) { // php 5.5+ $cFile = curl_file_create($file_name_with_full_path); } else { // $cFile = '@' . realpath($file_name_with_full_path); } $post = array('extra_info' => '123456','file_contents' => $cFile); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$target_url); curl_setopt($ch, CURLOPT_POST,1); curl_setopt($ch, CURLOPT_POSTFIELDS, $post); $result=curl_exec ($ch); curl_close ($ch); ?>
For additional information, you may also refer to:
https://blog.derakkilgo.com/2009/06/07/send-a-file-via-post-with-curl-and-php/
Note for PHP 5.5 :
For this version of PHP, you should use https://wiki.php.net/rfc/curl-file-upload instead. However, if you still want to follow the deprecated approach described above, ensure to set curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false); in your script.
The above is the detailed content of How Can I Transfer Uploaded Files to Another Server Using cURL in PHP?. For more information, please follow other related articles on the PHP Chinese website!

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

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)

Hot Topics

11 Best PHP URL Shortener Scripts (Free and Premium)

Working with Flash Session Data in Laravel

6 Extra Skills Every PHP Developer Should Have

Simplified HTTP Response Mocking in Laravel Tests

Build a React App With a Laravel Back End: Part 2, React

cURL in PHP: How to Use the PHP cURL Extension in REST APIs

12 Best PHP Chat Scripts on CodeCanyon
