Загрузка файла в общую папку на файловом сервере в PHP с использованием REST API ⇐ Php
Загрузка файла в общую папку на файловом сервере в PHP с использованием REST API
Currently I am trying to upload file from my PHP form to a file server (shared folder) via API. Files which are less than 65KB uploads fine, but when I try to upload 80KB or higher, it doesnt go into the shared folder. I have already configured my php.ini to accept 20MB (post_max_size & upload_max_filesize). I worried there are server configuration blocking my file upload, but I dont know where to check. I'm doing this project on my Window server 2019, appreciate it if anyone can help.
Below is my code to upload using API:
if (isset($_POST['on'])) { $tempfile = $_FILES['fileToUpload']['tmp_name']; $fileName = $_FILES['fileToUpload']['name']; $uploadUrl = 'http://APIURL/common/upload'; // Update this to the correct upload URL $curl = curl_init(); curl_setopt_array( $curl, array( CURLOPT_URL => $uploadUrl, CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_POSTFIELDS => array('file_id' => 'image', 'file' => new CURLFile($tempfile, 'image/jpeg', $fileName)), CURLOPT_HTTPHEADER => array( 'Content-Type: multipart/form-data' ), ) ); $response = curl_exec($curl); if ($response === false) { // An error occurred $error = curl_error($curl); $errno = curl_errno($curl); echo "cURL error ($errno): $error"; } else { // Upload was successful echo "File uploaded successfully!"; } curl_close($curl); }
Источник: https://stackoverflow.com/questions/781 ... g-rest-api
Currently I am trying to upload file from my PHP form to a file server (shared folder) via API. Files which are less than 65KB uploads fine, but when I try to upload 80KB or higher, it doesnt go into the shared folder. I have already configured my php.ini to accept 20MB (post_max_size & upload_max_filesize). I worried there are server configuration blocking my file upload, but I dont know where to check. I'm doing this project on my Window server 2019, appreciate it if anyone can help.
Below is my code to upload using API:
if (isset($_POST['on'])) { $tempfile = $_FILES['fileToUpload']['tmp_name']; $fileName = $_FILES['fileToUpload']['name']; $uploadUrl = 'http://APIURL/common/upload'; // Update this to the correct upload URL $curl = curl_init(); curl_setopt_array( $curl, array( CURLOPT_URL => $uploadUrl, CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_POSTFIELDS => array('file_id' => 'image', 'file' => new CURLFile($tempfile, 'image/jpeg', $fileName)), CURLOPT_HTTPHEADER => array( 'Content-Type: multipart/form-data' ), ) ); $response = curl_exec($curl); if ($response === false) { // An error occurred $error = curl_error($curl); $errno = curl_errno($curl); echo "cURL error ($errno): $error"; } else { // Upload was successful echo "File uploaded successfully!"; } curl_close($curl); }
Источник: https://stackoverflow.com/questions/781 ... g-rest-api
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Загрузка файла в общую папку на файловом сервере в PHP с использованием REST API
Anonymous » » в форуме Php - 0 Ответы
- 21 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Как пройти аутентификацию для FCM Rest API с помощью Google REST API в PHP REST API?
Anonymous » » в форуме Php - 0 Ответы
- 165 Просмотры
-
Последнее сообщение Anonymous
-