我在Yii框架中完成了文件上传的概念。数据存储正在存储到数据库中,但它没有存储到目录文件夹中。我在主目录中创建了书籍文件夹
我指定如下:
$ResumePath->saveAs(dirname(__FILE__).'/../../images/'.$model->ebook_name=$fileName);
目录是 项目名称/书籍/受保护。
请告诉我如何指定目录。
答案 0 :(得分:1)
试试这个。
$ResumePath=CUploadedFile::getInstance($model,'ebook_name');
$fileName="{$id}-{$ResumePath}"; //assuming can be put as a string, its an object? I'm not a Yii guy.
if (is_object($ResumePath) && get_class($ResumePath)==='CUploadedFile'){
$model->ebook_name=$fileName;
}
if($model->save()){
if(is_object($ResumePath))
$ResumePath->saveAs(dirname(__FILE__).'/../../books/'.$fileName);
解释,
$ResumePath=CUploadedFile::getInstance($model,'ebook_name');
$fileName="{$id}-{$ResumePath}"; //here you build the file name,
if (is_object($ResumePath) && get_class($ResumePath)==='CUploadedFile'){
$model->ebook_name=$fileName; //here you assign it to the $model whatever that is.
}
if($model->save()){
if(is_object($ResumePath))
$ResumePath->saveAs(dirname(__FILE__).'/../../books/'.$model->ebook_name=$fileName); //here you again assign it to the model, and output no file name.
然后最终结果是一个基本上像这样的文件名。
$ResumePath->saveAs(dirname(__FILE__).'/../../books/'; //no filename.
答案 1 :(得分:0)
$ResumePath=CUploadedFile::getInstance($model,'ebook_name');
$fileName="{$id}-{$ResumePath}";
if (is_object($ResumePath) && get_class($ResumePath)==='CUploadedFile'){
$model->ebook_name=$fileName;
}
if($model->save()){
if(is_object($ResumePath))
$ResumePath->saveAs(dirname(__FILE__).'/../../books/'.$model->ebook_name=$fileName);
这只有兄弟......我创建了文件夹名册。这是目录本身。