Trying to put info from files into database |
Hi there,
I am trying to scan through a specific folder (which will have images in) and for each one get the information and add them into a database. These files will already be uploaded onto the server so this is to be able to rebuild the information in the table. PHP Code: $this->db->truncate('gallery_images'); I have tested it and I know that it's not finding any files but I don't know why. Thanks, Doomie22
You cannot use the upload library for files that are already on the server.
You need to use the the directory helper to load the folder's file into an array. The file helper will give you some the information you want but I don't think you can get the image size, so you would need to use raw PHP or there maybe a library available but that I don't know. A good decision is based on knowledge and not on numbers. - Plato
ok atm I am not too bothered about the width and height then. I have tried the following but I am getting an "Invalid argument supplied for foreach()"
PHP Code: $this->db->truncate('gallery_images');
You don't need / should not have base_url in the path as this gives you a url (http://domain.ext/yourpath)
You need a physical path. Per the documentation: Paths are almost always relative to your main index.php file. So you should call PHP Code: $files = directory_map('./public/images/gallery/'); A good decision is based on knowledge and not on numbers. - Plato
I am seeing the files in the array but for some reason I am just getting null from this.
PHP Code: $get_info = get_file_info($file);
Does $file contain the the path or just the file name ?
Get_file_info need the path as well as the file name. You might be better of using just the file helper. PHP Code: $this->load->helper('file'); But I am not sure if this will include sub-folder. you will need to do a var_dump be sure. Have a look at the helpers documentation to see what is available. A good decision is based on knowledge and not on numbers. - Plato
Maybe this will help, not CI but works.
Read: 3. Recursive Directory Listing The Art of Web What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
|
Welcome Guest, Not a member yet? Register Sign In |