如何使用XAMPP在Laravel上传图像

时间:2014-03-26 09:58:01

标签: php forms laravel laravel-3

这是代码:

<div class="fileupload fileupload-new" data-provides="fileupload">
<div class="fileupload-new thumbnail" style="width: 270px; height: 270px;">
<img src="http://localhost/storage/images/moimage.gif" />
</div>
<div class="fileupload-preview fileupload-exists thumbnail" style="max-width: 270px; max-height: 270px; line-height: 20px;"></div>
<div>
<span class="btn btn-file"; style="width:100%">
<span class="fileupload-new"><?php echo __('site.select_image'); ?></span>
<span class="fileupload-exists"><?php echo __('site.change'); ?></span>
<input type="file" name="image" />
</span>
<a href="#" class="btn fileupload-exists" data-dismiss="fileupload">Delete</a>
</div>
</div>

这是行动:

if(Auth::can('upload_item_images'))
{
if(is_numeric($id) && Input::file('image.name') !== '')
{
$path = Config::get('application.upload_path') . DS . 'users' . DS . 'images' . DS .
$id . '.' . File::extension(Input::file('image.name'));
Bundle::start('resizer');
$success = Resizer::open(Input::file('image'))
->resize( 500 , 500 , 'crop' )
->save( $path , 90 );
}
}

这是应用程序upload_path:'upload_path' => path('public') . 'images'

我想将图像保存在图像/用户/图像中,但是当我上传图像时,它会拍摄出成功完成的消息,但实际上没有将图像添加到服务器中。

1 个答案:

答案 0 :(得分:0)

您必须在处理之前将图像保存到服务器。

if(Auth::can('upload_item_images'))
{
if(is_numeric($id) && Input::file('image.name') !== '')
{
$path = Config::get('application.upload_path') . DS . 'users' . DS . 'images' . DS .
$id . '.' . File::extension(Input::file('image.name'));
Bundle::start('resizer');
$name = Input::file('image')->getClientOriginalName();
Input::file('image')->move($name);
$success = Resizer::open($name)
->resize( 500 , 500 , 'crop' )
->save( $path , 90 );
}
}