发送到PHP上传图像文件的Andr​​oid图像文件的应用程序/八位字节流的类型,而不是为image / jpeg? [英] Android image file sent to php upload image file is application/octet-stream type and not image/jpeg?

查看:101
本文介绍了发送到PHP上传图像文件的Andr​​oid图像文件的应用程序/八位字节流的类型,而不是为image / jpeg?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好所有希望有人能能帮助 - 为了fininsh我的Andr​​oid应用程序,我只需要完成类是用户可以上载有图像服务器(MySQL的)。

Hello all hope someone can can help- To fininsh my android app I just need to finish the class were the user can upload there image to the server(MySql).

一切运作良好,除了除了图像的格式为应用程序/八位字节流,而不是从我的Andr​​oid应用程序发送的图像/ JPEG? 反正我有可以打开该文件的应用程序/八位字节流,并将其更改为图像/ JPEG类型??

All works well except except the format of the image is application/octet-stream rather than image/jpeg that is sent from my android app? Is there anyway I can open the file application/octet-stream and change it to a image/jpeg type??

上传PHP文件...

php file for upload...

$fileName = $_FILES['uploaded']['name'];

$tmpName = $_FILES['uploaded']['tmp_name'];

$fileSize = $_FILES['uploaded']['size'];

$fileType = $_FILES['uploaded']['type'];


$fp      = fopen($tmpName, 'rb');
$content = fread($fp, $fileSize);
$content = addslashes($content);

与表单上传表单没问题的工程确定。但是从Android应用程序与错误的图像类型时它节省了BLOB文件为空0,$作品尺寸显示的真实大小,但在$内容时,它显示什么都没有

Works ok with a form upload form no problem there. But when used from the android app with the wrong image type it saves the blob file as empty 0, $fileSize shows the true size but when $content is created it shows nothing at all

177罗马2.JPG图像/ JPEG 6876 [BLOB - 6.7昆明植物P(这是从网页) 215 myImage.jpg应用程序/八位字节流1066 [BLOB - 0 B](从手机)

177 rome 2.jpg image/jpeg 6876 [BLOB - 6.7 KiB] p (This is from a web page) 215 myImage.jpg application/octet-stream 1066 [BLOB - 0 B] (From phone)

THX家伙

推荐答案

应用程序/八位字节流为image / jpeg 仅是mime类型的HTTP客户端(浏览器)增加作为附加信息旁边的二进制文件数据本身。

application/octet-stream or image/jpeg is only the mime-type the HTTP client (browser) has added as additional information next to the binary file-data itself.

因此​​,MIME类型应该是没有什么问题的这里。它只是你看到你的程序出现故障的情况下请求之间的差异,但这不能是你的问题的原因。

So the mime-type shouldn't be of any issue here. It's just that you see a difference between the requests for the case your program fails, but this must not be the cause of your issue.

所以你基本上是在寻找错误的地方。

So you're basically looking at the wrong place.

相反,你应该添加错误和状况检查,您的code。特别的 precondition检查的,让你知道你的脚本可以正常上它被提供的数据进行操作。

Instead you should add error and condition checking to your code. Especially precondition checks so that you know that your script can properly operate on the data it gets provided.

这是什么您已经于您的问题可见,没有什么特别,我可以添加。希望这是有帮助的呢。

From what you have made visible in your question, there is nothing more specifically I can add. Hope this is helpful anyway.

另外,PHP手册有有关文件上传部分这包含了一些有用的信息包括。处理错误的案件。

Also the PHP Manual has a section about file-uploads which contains some useful information incl. dealing with error-cases.

下一步,你的code可能只是你如何将数据插入到你的数据库有问题,所以这个问题可能不会在所有的有关文件上传技术。

Next to that your code might just have a problem with how you insert the data into your database, so the problem might not be related at all with the file-upload technically.

这篇关于发送到PHP上传图像文件的Andr​​oid图像文件的应用程序/八位字节流的类型,而不是为image / jpeg?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆