【问题标题】:Change mime type pictures before save it on server在将其保存在服务器上之前更改 mime 类型的图片
【发布时间】:2015-11-08 19:11:56
【问题描述】:

我有代码:

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

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

【问题讨论】:

  • 您只需要在将图像提供给浏览器时进行 MIME 类型。如果您只是将其保存为服务器上的文件,那么您所做的应该没问题。

标签: php image converter mime


【解决方案1】:

如果你只是将图片上传到服务器上,那么你不需要使用

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

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

move_uploaded_file ( string $filename , string $destination )

【讨论】:

    猜你喜欢
    • 2023-03-15
    • 2015-11-07
    • 1970-01-01
    • 1970-01-01
    • 2013-03-07
    • 1970-01-01
    • 2017-01-26
    • 2021-09-29
    • 1970-01-01
    相关资源
    最近更新 更多