Welcome Guest, Not a member yet? Register   Sign In
Image Upload Path
#1

[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?
#2

[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 '/'
#3

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

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

[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!




Theme © iAndrew 2016 - Forum software by © MyBB