如何通过我的API

时间:2016-01-19 09:57:39

标签: php api laravel-4

我正在使用Laravel 4.2开发API。使用Postman测试我的方法。

由于尺寸原因,通过API上传图片无法获得任何响应。

当我上传image.icon时,它会成功返回。

但是当我做image.jpg(大小:2MB)时它返回: Could not get any response

没有400,401等代码

PHP信息:

max_execution_time          10000
max_file_uploads:           20
max_input_nesting_level:    64
max_input_time:             60
max_input_vars:             1000
memory_limit:               1024M
post_max_size:              5000M
upload_max_filesize         5000M

代码:

$attachment = Input::file('attachment');

如何上传超过2MB的图片?

htaccess的:

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    php_value post_max_size 200M
    php_value upload_max_filesize 200M

    # Redirect Trailing Slashes...
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]

    LimitRequestBody 102400

</IfModule>

截图: enter image description here

2 个答案:

答案 0 :(得分:2)

您需要更改PHP设置以允许更大的上传。 PHP对许多方面都有限制。 POST大小,上传大小等。

注意post_max_size应大于upload_max_filesize

; Maximum size of POST data that PHP will accept.
; Its value may be 0 to disable the limit. It is ignored if POST data reading
; is disabled through enable_post_data_reading.
; http://php.net/post-max-size
post_max_size = 125M

; Maximum allowed size for uploaded files.
; http://php.net/upload-max-filesize
upload_max_filesize = 100M

; Maximum number of files that can be uploaded via a single request
max_file_uploads = 20

通过.Htaccess

您还可以通过.htaccess文件增加上传限制: -

RewriteEngine on

之后写下这一行
php_value post_max_size 200M
php_value upload_max_filesize 200M

在你的情况下

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    php_value post_max_size 200M
    php_value upload_max_filesize 200M

    # Redirect Trailing Slashes...
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]

    LimitRequestBody 102400

</IfModule>

答案 1 :(得分:1)

检查你的php.ini文件。您可以将php.ini设置编辑为

upload_max_filesize = 8M 
post_max_size = 8M

或者您可以使用

ini_set('upload_max_filesize', '8M');