Skip to content
Advertisement

Unlink file – path issue – Codeigniter

Apparently, I am confused how to use site_url() while deleting a file.

My site_url responded with http://localhost/Project/index.php

For deleting a file, I use unlink command. However, How to use site_url into the unlink command in codeigniter. I am surprised!

Below is the path where the uploaded files get stored!

$config['upload_path']      = './assets/images';

I have used the following:

unlink($_SERVER['DOCUMENT_ROOT']."/NetSach/assets/images/".$_FILES['picture']['name']);

Message: unlink(C:/xampp/htdocs/NetSach/assets/images/sweepers cartoon.jpg): No such file or directory

Advertisement

Answer

Sorry about the innocent question. I hope I understood the question than others would! However, I tried the below and found it working finally!

unlink($_SERVER['DOCUMENT_ROOT'].'/project_folder/assets/images/'.$res['image_url']);

$_SERVER['DOCUMENT_ROOT'] // Gives the root path of the project folder successfully.

I use the codeigniter way of the path. i.e.) The base_url() is not working in the unlink because it will not accept https://

I hope this answer will be useful to someone!

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement