Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

deleting a image file yii

Tags:

file-io

image

yii

can any one pls tell me how to delete an image file and directory in yii

I have tried unlink but its not working.(the path is correct but its not deleting) but getting the error No such file or directory

unlink(Yii::app()->request->baseUrl.'/uploads/'.$model->file_id.'/'.$fileModel->file_name.$fileModel->extension);
  • and I also need to delete a directory in yii framework.the path is correct but its not deleting

    rmdir(Yii::app()->request->baseUrl.'/uploads/'.$model->file_id);

This is not working either, but getting the error No such file or directory.

like image 611
Developer Avatar asked Dec 04 '12 14:12

Developer


3 Answers

Try:

unlink(getcwd().'/uploads/'.$model->file_id.'/'.$fileModel->file_name.$fileModel->extension);

getcwd() gets the current working directory. The docs for it are here

like image 57
Brett Gregson Avatar answered Sep 24 '22 15:09

Brett Gregson


Instead of

Yii::app()->request->baseUrl

Try

Yii::app()->basePath

like image 32
jborch Avatar answered Sep 24 '22 15:09

jborch


I have never used Yii's earlier versions.

For Yii2: unlink(Yii::$app->basePath.'/directory_path/'.$filename);

like image 30
shairya Avatar answered Sep 23 '22 15:09

shairya