0

我有一个带有表单的页面,用户可以在其中上传图像以替换他现有的头像。

但是,如果用户提交表单而不上传图片,我不会更新他的头像,用户可以保留他的旧头像。

这是一个更新问题,所以我需要这样的伪代码:

if (Input::has_uploaded_file() === true)
    //User uploaded something, update avatar column/remove old avatar etc.
else
    //User didn't upload anything so don't update avatar column

不过,我只需要第一行。

有人可以帮忙吗?我在文档中找不到太多关于此的内容。

4

2 回答 2

3

If Input::has_file('name') does not work for you then you can use the equivalent of what it is doing, like this...

if (Input::file('name.tmp_name', '') != '')

Taken from laravel/input.php

于 2013-04-11T00:31:52.290 回答
0

I read laravel source code, i think its this:

Input::has_file('input_name');

If that's not work, try using native php:

$_FILES['input_name']['error'] = UPLOAD_ERR_NO_FILE;

Or same above with laravel:

$i = Input::file('input_name');

$i['error'] = UPLOAD_ERR_NO_FILE;

Code above is to check if user leave the upload form empty.

于 2013-04-11T00:21:08.477 回答