[eluser]linderox[/eluser]
I want to make a cool my own photogallery
I want to upload to directory some image files and read directory with files to the database.
But I have 2 problems:
1) get_filenames function reads files from the subdirectory folder (e.g. thumbs) and I get more than I want to get lines to my db.
2) I don't know how to add character $img_suffix to the place before type of the file.
I want to read SomeImgFile.jpg and than automaticaly add to the database place of the thumbfile SomeImageFile_cr.jpg
here is my code with my ideas.Can you help me to solve this problems or give me your ideas how to update my database with list of files.
Code:
function FillUpDatabaseWithPhoto($directory)
{
$pathtothumb = '/sm/';
$imgsuffix = '_cr';
$this->load->helper('file');
$this->load->database('photostock');
$filesarray=get_filenames("public/images/$directory",FALSE);
echo $filesarray." <br>\n" ;
foreach ($filesarray as $imgfile) {
$array = array('originalpath' => "$directory/$imgfile", 'thumbpath' => "$directory.$pathtothumb.$imgfile.$imgsuffix", 'gid' => "$directory");
$this->db->set($array);
$this->db->insert('photostock');
/*$this->gallery_model->additem($data); */
echo "$imgfile \n <br>";
}
}
here what i should get in my database. I have 12 files and thumb directory inside with 12 thumb files
Code:
050sq.jpg 050sq_cr.jpg
but I get in my database such thing. I get 24 rows with stuff like this:
Code:
050sq.jpg 050sq.jpg_cr // added "_cr" to the end, but I need "_cr.jpg"
050sq_cr.jpg 050sq_cr.jpg_cr // excess line