(Symfony 4,Amazon Linux 2)无法上传大文件

时间:2019-03-13 20:33:23

标签: file upload symfony4

每当我尝试上传大约3 MB的文件时,当我尝试进行转储并查看文件时,都会收到以下消息:

stream_socket_sendto(): Connection refused

如果我尝试调用上载文件对象上的任何函数(即$file->getPathName()$file->getClientOriginalName()),它只会返回一个空字符串。因此,不得上传文件。

我可以轻松地转储并查看上传的.gif小文件,因此,只有在上传大文件时才会出现错误。

这是我的Photo类的Symfony注释的外观:

class Photo
{

/**
 * @ORM\Column(type="string")
 * @Assert\NotBlank(message="File was not uploaded!")
 * @Assert\File(
 *     maxSize="1000M",  // allowing 1 gigabyte upload size
 *     mimeTypes = {"application/gif", "image/png", "image/jpg", "image/jpeg"},
 *     mimeTypesMessage = "Please upload a valid image type (.jpg, .jpeg, .png, .gif)"
 * )
 */
private $file;

在我的php.ini文件中,upload_max_filesize设置如下:

upload_max_filesize = 1000M

这是我的Nginx配置文件:

server {
    server_name www.myhost.com;
    root /var/www/vhosts/myhost.com/public;

    client_max_body_size 1000M;

    location / {
        # try to serve file directly, fallback to index.php
        try_files $uri /index.php$is_args$args;
    }

    location ~ ^/index\.php(/|$) {
        fastcgi_pass unix:/var/run/php-fpm.sock;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;

        # optionally set the value of the environment variables used in the application
        # fastcgi_param APP_ENV prod;
        # fastcgi_param APP_SECRET <app-secret-id>;
        # fastcgi_param DATABASE_URL "mysql://db_user:db_pass@host:3306/db_name";

        # When you are using symlinks to link the document root to the
        # current version of your application, you should pass the real
        # application path instead of the path to the symlink to PHP
        # FPM.
        # Otherwise, PHP's OPcache may not properly detect changes to
        # your PHP files (see https://github.com/zendtech/ZendOptimizerPlus/issues/126
        # for more information).
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        fastcgi_param DOCUMENT_ROOT $realpath_root;
        # Prevents URIs that include the front controller. This will 404:
        # http://domain.tld/index.php/some-path
        # Remove the internal directive to allow URIs like this
        internal;
    }

    # return 404 for all other php files not matching the front controller
    # this prevents access to other php files you don't want to be accessible.
    location ~ \.php$ {
        return 404;
    }

    error_log /var/log/nginx/project_error.log;
    access_log /var/log/nginx/project_access.log;
}

有人知道为什么我无法加载大文件吗?

0 个答案:

没有答案
相关问题