我想将图像保存到cakephp图像uploadify中运行时的子目录

时间:2012-11-04 21:47:08

标签: jquery cakephp cakephp-2.0

我试试这个..但是没有创建子文件夹...我不明白问题出在哪里..

$user_id = $this->User->id;
if(!empty($prof_image['name'])){
$image_name = str_replace($prof_image['name'], 'profile', $prof_image['name']);
$dest = WWW_ROOT . DS . 'img' . DS . 'filocity_img' . DS . 'user_'. $user_id . DS . $image_name . '.jpg';
if(move_uploaded_file($prof_image['tmp_name'], $dest)){
    echo json_encode('Information successfully updated');
}
}
谁能帮助我吗?提前谢谢。

2 个答案:

答案 0 :(得分:1)

  

但不创建子文件夹

如果要将图像保存在不存在的子目录中,则必须在调用move_uploaded_file()之前创建它

The destination directory must exist; move_uploaded_file() will not automatically create it for you

如果这不是问题,那么您需要在问题中提供更多详细信息。

答案 1 :(得分:0)

您可以使用CakePHP文件和文件夹实用程序轻松完成。

首先添加:

<?php 
App::uses('Folder', 'Utility');
App::uses('File', 'Utility');

然后试试这个:

$user_id = $this->User->id;
if(!empty($prof_image['name'])){
   $image_name = str_replace($prof_image['name'], 'profile', $prof_image['name']);
   $dest = WWW_ROOT . DS . 'img' . DS . 'filocity_img' . DS . 'user_'. $user_id;
 $dir = new Folder($dest, true, 0777);
 $file = new File($dir. DS . $image_name . '.jpg');
 if($file){
    echo json_encode('Information successfully updated');
   }

}