CodeIgniter Forums
Image Upload Path - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Image Upload Path (/showthread.php?tid=58596)



Image Upload Path - El Forum - 06-28-2013

[eluser]Felipe Deitos[/eluser]
Hi!

I got a newbie question, actually everything is working but everytime i put the code from my localhost to webserver e need to change the separator of the path... take a look at the code:

In every model that i need to delete images i have this:
Code:
var $image_folder;
function __construct() {
    parent::__construct();
    $this->load->library('upload');
    $this->image_folder = realpath(APPPATH . '../assets/images/products');
}
function delete_image($id){
    $image = $this->get($id);
    unlink($this->image_folder."\\".$image->image);  \\ here i need to change it everytime

    $this->db->where('id', $id);
    $delete= $this->db->delete('products');
    return $update;
}

The image_folder in localhost returns C:\xampp\htdocs\www\something\assets\images\products so i need to use "\\".
In webserver the image_folder returns http://www.something.com.br/assets/images/products and i need to use "/".

Am i doing something wrong? What else can i do to stop changing this //\/\/\/\/\/\/\/\ everytime?


Image Upload Path - El Forum - 06-28-2013

[eluser]jvicab[/eluser]
You can use DIRECTORY_SEPARATOR php constant to get the correct separator based on the OS: ussually Windows is '\' but LINUX is '/'


Image Upload Path - El Forum - 06-28-2013

[eluser]Ckirk[/eluser]
Windows should be able to handle the "/". Mine does so I never have to change it on my local machine


Image Upload Path - El Forum - 06-28-2013

[eluser]Pert[/eluser]
Yeah, backslash works for everything


Image Upload Path - El Forum - 07-02-2013

[eluser]Felipe Deitos[/eluser]
Sorry for taking too long to give you guys one feedback.
Yes, i was wrong... It works with backslash in both local and webserver...

I really doesnt know what i was doing wrong, but now everything is working.

Cheers everybody!