【发布时间】:2015-01-03 16:14:20
【问题描述】:
我正在尝试使用 cakephp 和 mysql 显示图像。我的代码正在运行,但它没有显示图像 uploadsController 是::
<?php
class UploadsController extends AppController{
var $name='Uploads';
function share_video($stu_id=null)
{
$this->set('stu',$stu_id);
$tut=$this->Session->read('tutor_id');
$data=$this->Upload->query("select * from tutors AS Tutor where tutor_id='$tut'");
$this->set('val1',$data);
if (!empty($this->data)) {
$this->Upload->create();
if ($this->uploadFile() && $this->Upload->save($this->data)) {
$this->Session->setFlash(__('The upload has been saved', true));
//$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The upload could not be saved. Please, try again.', true));
}
}
$data=$this->Upload->find('all');
$this->set('val2',$data);
$this->layout='tutor';
}
function uploadFile() {
$id = mysql_insert_id();
$file = $this->data['Upload']['file'];
if ($file['error'] === UPLOAD_ERR_OK) {
//$id = String::uuid();
if (move_uploaded_file($file['tmp_name'], APP.'webroot/uploads'.DS.$file['name'])) {
$this->request->data['Upload']['upload_id'] = $id;
$this->request->data['Upload']['filename'] = $file['name'];
$this->request->data['Upload']['filesize'] = $file['size'];
$this->request->data['Upload']['filemime'] = $file['type'];
return true;
}
}
return false;
}
function download($filename=null)
{
$data=$this->Upload->find('all',array('conditions'=>array('filename'=>$filename)));
$this->set('val1',$data);
}
}
?>
我的 download.ctp 文件是:
html->image('uploads/'.$val1[0]['Upload']['filename']); //echo 'Html->url(array('controller' => 'uploads','action' => 'download',$val1[0]['Upload']['filename'])).'" 宽度="100" 高度="100"/>'; ?>【问题讨论】:
-
echo $this->Html->image('uploads/'.$val1['Upload']['filename'],array('class'=>'media-object img img- thumbnail','alt'=>$val1['Upload']['filename']) );
-
此代码不起作用
-
你能打印 $data 中的输出吗?
-
Array ( [0] => Array ( [Upload] => Array ( [upload_id] => 1 [tutor_id] => 6 [stu_id] => 3 [grade] => X [subject ] => Maths [filename] => 2014-09-29 12_19_42-Greenshot.png [filesize] => 1679057 [filemime] => image/png ) ) ) 这是打印 $data 后的输出
-
$data=$this->上传->find('first',array('conditions'=>array('filename'=>$filename)));
标签: cakephp