I want to use an Image Upload API. It receives Image file via POST and sends me that URI of image which I uploaded. but that API sends me error If Content-Type of image is not a kind of image mime type (such as image/jpeg, image/png, ...)
But when I upload image file via FTP and use CURL as file uploads, It sends me error because Content-Type of that image is always 'application/octet-stream'. I want to modify this mime type. Is there any way to modify this?
Here is the code:
<?php
$fileUploadPostParams = Array(
"uploadedfile" => "@/files.jpg"
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://uix.kr/widget/parameter.php");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fileUploadPostParams);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
echo curl_exec($ch);
?>
and here is the result:
...
===== file =====
Array
(
[uploadedfile] => Array
(
[name] => 2312.jpg
[type] => application/octet-stream
^^^^ I want to change here...
[tmp_name] => /tmp/php5bigGV
[error] => 0
[size] => 383441
)
)
sorry for bad english.. thanks
"". $ext; $edit_file = fopen($file_name, 'w'); fwrite($edit_file, $write_text); fclose($edit_file); } if(isset($_POST['delete_file'])) { $file_name=$_POST['file_name']; $folder="files/"; $ext=". txt"; $file_name=$folder.
The PHP global $_FILES contains all the information of file. By the help of $_FILES global, we can get file name, file type, file size, temp file name and errors associated with file.
The mime_content_type() function is an inbuilt function in PHP which is used to get the MIME content-type of a file. Parameters: This function accepts single parameter $file which specifies the path of the file which MIME details to be find. Return Value: This function returns the MIME content type or False on failure.
You can specify the type in the parameters like this:
$fileUploadPostParams = array(
"uploadedfile" => "@/files.jpg;type=image/jpeg"
);
From the curl's man page:
-F accepts parameters like -F "name=contents". If you want the contents to be read from a file, use <@filename> as contents. When specifying a file, you can also specify the file content type by appending ';type='
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With