当请求为ajax时,无法验证Laravel 4中的文件上传


Unable to validate file upload in Laravel 4 when request is ajax

我在validate方法内的BaseModel中有这段代码:

foreach(Input::file() as $key => $value)
{
    (!empty($value)) ? $this->attributes[$key] = Input::file($key) : $this->attributes[$key] = '';
}

这使我能够将文件验证与其他输入验证集成在一起。使用规则requiredmimes:png,它可以正常工作。

但是,对于ajax请求,我总是收到$this->attributes[$key] = ''

在Laravel 4中通过ajax上传文件时有什么问题吗?

假设它是您的上传脚本,而不是Laravel。您不能简单地通过通常的ajax请求发送文件。如何使用ajax查看以表单上传的文件?