繁体   English   中英

更改mime类型的图片,然后再将其保存在服务器上

[英]Change mime type pictures before save it on server

我有代码:

//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);

问题在于它是此时的标题(“ Content-Type:图片/ gif”); 在浏览器中显示图像。 如何更改mime类型不会将结果输出到浏览器。 将所有图像以gif格式和类型保存在服务器上的最终目的。

如果您只是将映像上传到服务器,则无需使用

header('Content-Type: image/gif');// remove this

它用于将图像文件输出到浏览器。 如果一切正常,则使用php文件上传功能上传文件

move_uploaded_file ( string $filename , string $destination )

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM