【发布时间】:2014-12-25 08:03:28
【问题描述】:
我努力想知道但无法解决,然后我来这里寻求您的帮助。请不要介意它是否超出主题,也请忍受我糟糕的英语。
当我打开 http://localhost/cakephp/posts 时,我正在尝试在 cakephp 2.x 中上传图像,然后正确上传图像,但是当我打开 http://localhost/cakephp/posts/index 时,图像不会上传。并收到错误“未找到”。
我正在使用blueimp image uploader。
我查看了它的文档,但找不到解决方案。
还有一件事,索引页面中有表单,点击上传按钮<form id="fileupload" action="posts/index" method="POST" enctype="multipart/form-data">提交
编辑
动作代码
public function index() {
$options = array(
'upload_dir' => 'img',
'accept_file_types' => '/\.(gif|jpe?g|png)$/i',
);
$upload_handler = new UploadHandler($options);
}
查看代码
<form id="fileupload" action="posts/index" method="POST" enctype="multipart/form-data">
<!-- Redirect browsers with JavaScript disabled to the origin page -->
<noscript><input type="hidden" name="redirect" value="https://blueimp.github.io/jQuery-File-Upload/"></noscript>
<!-- The fileupload-buttonbar contains buttons to add/delete files and start/cancel the upload -->
<div class="row fileupload-buttonbar">
<div class="col-lg-7">
<!-- The fileinput-button span is used to style the file input field as button -->
<span class="btn btn-success fileinput-button">
<i class="glyphicon glyphicon-plus"></i>
<span>Add files...</span>
<input type="file" name="files[]" multiple>
</span>
<button type="submit" class="btn btn-primary start">
<i class="glyphicon glyphicon-upload"></i>
<span>Start upload</span>
</button>
<button type="reset" class="btn btn-warning cancel">
<i class="glyphicon glyphicon-ban-circle"></i>
<span>Cancel upload</span>
</button>
<button type="button" class="btn btn-danger delete">
<i class="glyphicon glyphicon-trash"></i>
<span>Delete</span>
</button>
<input type="checkbox" class="toggle">
<!-- The global file processing state -->
<span class="fileupload-process"></span>
</div>
<!-- The global progress state -->
<div class="col-lg-5 fileupload-progress fade">
<!-- The global progress bar -->
<div class="progress progress-striped active" role="progressbar" aria-valuemin="0" aria-valuemax="100">
<div class="progress-bar progress-bar-success" style="width:0%;"></div>
</div>
<!-- The extended global progress state -->
<div class="progress-extended"> </div>
</div>
</div>
<!-- The table listing the files available for upload/download -->
<table role="presentation" class="table table-striped"><tbody class="files"></tbody></table>
</form>
【问题讨论】:
-
你应该发布你的代码,至少控制器,查看代码。
-
这一行在控制器之前开始 App::import('Vendor', 'UploadHandler', array('file' => 'file.upload/UploadHandler.php'));这是行动 public function index() { $options = array( 'accept_file_types' => '/\.(gif|jpe?g|png)$/i', ); $upload_handler = new UploadHandler($options); }
-
我没有答案,但我认为这个解决方案简单实用:bakery.cakephp.org/articles/tutec/2010/01/05/…
-
请看现在,现在可能会给出代码指南来帮助我。
标签: cakephp file-upload image-uploading