[英]Change mime type pictures before save it on server
I have code: 我有代码:
//Get image from form
$image = $_FILES['image']['tmp_name'];
//Convert to base64
$imageData = base64_encode(file_get_contents($image));
//Set mime type
header('Content-Type: image/gif');
//Decode to image
$image = base64_decode($imageData);
//Save in server
$res = file_put_contents(ROOT_DIR . "/uploads/fotos/" . $row['user_id'] . ".gif", $image);
The problem is that it is at this point header ('Content-Type: image / gif'); 问题在于它是此时的标题(“ Content-Type:图片/ gif”); displays the image in the browser.
在浏览器中显示图像。 How do I change the mime type does not output the result to the browser.
如何更改mime类型不会将结果输出到浏览器。 The ultimate goal of saving all the images on a server in the format and type of gif.
将所有图像以gif格式和类型保存在服务器上的最终目的。
If you are just uploading the image onto the server then you need not to use 如果您只是将映像上传到服务器,则无需使用
header('Content-Type: image/gif');// remove this
it is used to output the image file to the browser. 它用于将图像文件输出到浏览器。 if everything is ok then to upload file use php file upload function
如果一切正常,则使用php文件上传功能上传文件
move_uploaded_file ( string $filename , string $destination )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.