简体   繁体   English

在cakephp中上传文件

[英]file uploading in cakephp

Hey there, I'm using the tutorial at http://www.jamesfairhurst.co.uk/posts/view/uploading_files_and_images_with_cakephp to try to get myself up and running with the ability to upload images. 嘿,我正在使用http://www.jamesfairhurst.co.uk/posts/view/uploading_files_and_images_with_cakephp上的教程来尝试使自己起跑并具有上载图像的能力。

Now, I'm very new, and really haven't a clue so this is probably the most stupid question in the world but I don't know whats going on. 现在,我很新,并且真的没有任何线索,所以这可能是世界上最愚蠢的问题,但我不知道发生了什么。

Basically I follow the tutorial as best I can but when I load the page which is supposed to have the input for the image I get the rest of the form but then get 2 errors: Method FormHelper::labelTag does not exist and Method HtmlHelper::file does not exist 基本上,我会尽全力按照本教程进行操作,但是当我加载应该包含图像输入的页面时,我得到了表单的其余部分,但是遇到了2个错误:FormFormer :: labelTag方法不存在,而HtmlHelper方法: :文件不存在

I've searched but only got more confused. 我进行了搜索,但更加困惑。 There is something I'm meant to include that i've missed isn't there? 我本来想包括的东西不存在吗?

confused... 困惑...

I assume you've put the uploadFiles function in to your APP/app_controller.php 我假设您已将uploadFiles函数放入您的APP/app_controller.php

You would do something like this in your add action, for instance: 您可以在add操作中执行以下操作,例如:

$fileData = $this->uploadFiles('img/uploads', $this->data['File']);
print_r($fileData);

What version of Cake are you using? 您使用的是哪个版本的Cake? That tutorial is quite old, and whilst the upload functionality still works fine, the labelTag and File methods are now deprecated (as of 1.3 I think). 该教程已经很老了,尽管上传功能仍然可以正常使用,但不推荐使用labelTagFile方法(我认为从1.3开始)。 you should use: 您应该使用:

echo $this->Form->label('image', 'Image');
echo $this->Form->file('File.image');

instead, and you should be good to go. 相反,您应该很好。

edit You can also just use echo $this->Form->input('File.range_image', array('type'=>'file')); 编辑您也可以只使用echo $this->Form->input('File.range_image', array('type'=>'file'));

as if I recall, that's the preferred way ~ 好像我记得,那是首选的方式〜

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM