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.
Try:
unlink(getcwd().'/uploads/'.$model->file_id.'/'.$fileModel->file_name.$fileModel->extension);
getcwd()
gets the current working directory. The docs for it are here
Instead of
Yii::app()->request->baseUrl
Try
Yii::app()->basePath
I have never used Yii's earlier versions.
For Yii2: unlink(Yii::$app->basePath.'/directory_path/'.$filename);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With