图像在上传时不断改变文件类型

发布于 2025-01-16 05:28:39 字数 967 浏览 3 评论 0原文

当尝试上传图像时,mimetype 不断从 imaage/jpg 更改为 application/octet-stream,我不知道为什么,因为我可以上传相同的图像 5 次,每次都会给出不同的 mimetype,有没有办法强制 laravel 或 vue.js 将 application/octet-stream 转换为图像类型? 这是我的 HTML

<input type="file" id="banner" name="filename">

这是我使用惯性.js 的 vue.js post 请求

this.$inertia.post(route('user.edit', this.user.id), object,{
            onSuccess: () => {
                this.sweetAlertSuccess(attribute); // fire success message
                axios.get('/user/' + this.user.id).then(resp => {
                    resp.data.media.forEach(el => {
                        if(el.collection_name === 'banner'){
                            this.banner = el.original_url;
                        }
                        if(el.collection_name === 'avatar'){
                            this.avatar = el.original_url;
                        }
                    });
                });
            }

When trying to upload an image, the mimetype keeps changing from imaage/jpg to application/octet-stream, I have no clue why because I could upload the same image 5 times and each time could give a different mimetype, is there a way to force laravel or vue.js to make application/octet-stream into an image type?
here is my HTML

<input type="file" id="banner" name="filename">

Here is my vue.js post request using inertia.js

this.$inertia.post(route('user.edit', this.user.id), object,{
            onSuccess: () => {
                this.sweetAlertSuccess(attribute); // fire success message
                axios.get('/user/' + this.user.id).then(resp => {
                    resp.data.media.forEach(el => {
                        if(el.collection_name === 'banner'){
                            this.banner = el.original_url;
                        }
                        if(el.collection_name === 'avatar'){
                            this.avatar = el.original_url;
                        }
                    });
                });
            }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

等风也等你 2025-01-23 05:28:39

发生这种情况是因为您的服务器不接受图像的重量,并且默认情况下它会更改 mime 类型,请修改 php.ini 中的以下变量

(要找到此文件,请检查 phpinfo( ); 函数)

<?php
    phpinfo();
?>
upload_max_filesize = 60M
post_max_size = 60M

默认值是2M,根据自己的需要设置这个值,修改php.ini文件后,需要重启HTTP服务器才能使用新配置。

可能需要以下任何命令:

service apache2 restart
service httpd restart
service php-fpm restart

This happens because your server is not accepting the weight of the images and by default it changes the mime type, modify the following variables in the php.ini

(to locate this file check the phpinfo(); function)

<?php
    phpinfo();
?>
upload_max_filesize = 60M
post_max_size = 60M

The value by default is in 2M, set this value according to yours need, after modifying php.ini file(s), you need to restart your HTTP server to use the new configuration.

May be need any of this commands:

service apache2 restart
service httpd restart
service php-fpm restart
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文