【问题标题】:Unable to send file type to the server无法将文件类型发送到服务器
【发布时间】:2013-08-19 14:10:32
【问题描述】:

在将图像上传到 PHP 服务器时,我以这种方式将其作为文件发送:

entity.addPart("image_file", new FileBody(new File(file_path)));
httppost.setEntity(entity);

但是在服务器端我得到了错误:

您尝试上传的文件类型不允许

因为正在发送的数据是:

[image_file] => Array
    (
        [name] => IMG_20130801_124102.jpg
        [type] => 
        [tmp_name] => C:\wamp\tmp\php37E.tmp
        [error] => 0
        [size] => 2084727
    )

类型没有价值。

据我所知,它应该会自动进行。还是我应该把它设置在某个地方?

【问题讨论】:

    标签: php android image-uploading


    【解决方案1】:

    您可以检查以下内容:

    1. 如果“jpg”在 PHP 配置文件中设置为允许的类型。
    2. 如果您尝试上传的图像超过了 php.ini 文件中设置的“upload_max_filesize”。您可以使用较小的图像进行测试,看看它是否有任何变化。

    【讨论】:

    • 是的,我检查了 1。 $config['allowed_types'] = 'gif|jpg|jpeg|png'; 2。对于尺寸问题,我收到一条不同的消息: The uploaded file exceeds the maximum allowed size in your PHP configuration file.
    • 试试这个:entity.addPart("image_file", new FileBody(new File(file_path), "image/jpeg"));
    猜你喜欢
    • 2015-01-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-12
    • 1970-01-01
    • 2021-12-05
    • 1970-01-01
    相关资源
    最近更新 更多