/** * Move uploaded files in the associated album directory and insert metadata in the database * * @access private */ private function create() { if (VPost::upload(false) && !empty($_FILES)) { try { $album = new Media(); $album->_id = VPost::album_id(); $album->read('_name'); $album->read('_permalink'); $path = $album->_permalink; foreach (VFiles::all() as $key => $img) { if (empty($img['name'])) { continue; } $pic = new HandleMedia(); $pic->load_upload($key); $name = Helper::remove_accent($pic->_name); $mime = $pic->_mime; if (substr($mime, 0, 5) == 'image') { if (file_exists(PATH . $path . $name)) { throw new Exception('The file "' . $name . '" already exists'); } $pic->save(PATH . $path . $name); $pic->thumb(150, 0); $pic->thumb(300, 0); $pic->thumb(1000, 0); $picture = new Media(); $picture->_name = $name; $picture->_type = $mime; $picture->_author = $this->_user['user_id']; $picture->_album = $album->_id; $picture->_allow_comment = 'closed'; $picture->_permalink = $path . $name; $picture->_status = 'publish'; $picture->create(); } } Session::monitor_activity('added new photos to ' . $album->_name); $result = true; } catch (Exception $e) { $result = $e->getMessage(); } $this->_action_msg = ActionMessages::created($result); } elseif (VPost::upload_zip() && !empty($_FILES)) { try { $album = new Media(); $album->_id = VPost::album_id(); $album->read('_name'); $album->read('_permalink'); $path = $album->_permalink; $tmp = 'tmp/albums/'; if (empty($_FILES['zip']['tmp_name'])) { throw new Exception('No archive uploaded!'); } File::unzip($_FILES['zip']['tmp_name'], $tmp); $files = @scandir($tmp); if (empty($files)) { throw new Exception('Your archive is empty!'); } foreach ($files as $file) { $finfo = new finfo(FILEINFO_MIME_TYPE); $mime = $finfo->file($tmp . $file); if ($mime == 'directory') { continue; } $pic = new HandleMedia(); $pic->_mime = $mime; $pic->load($tmp . $file); $name = Helper::remove_accent($pic->_name); if (substr($mime, 0, 5) == 'image') { if (file_exists(PATH . $path . $name)) { throw new Exception('The file "' . $name . '" already exists'); } File::read($tmp . $file)->save(PATH . $path . $name); $pic->_file = PATH . $path . $name; $pic->thumb(150, 0); $pic->thumb(300, 0); $pic->thumb(1000, 0); $picture = new Media(); $picture->_name = $name; $picture->_type = $mime; $picture->_author = $this->_user['user_id']; $picture->_album = $album->_id; $picture->_allow_comment = 'closed'; $picture->_permalink = $path . $name; $picture->_status = 'publish'; $picture->create(); File::delete($tmp . $file); } } Session::monitor_activity('added new photos to ' . $album->_name); $result = true; } catch (Exception $e) { $result = $e->getMessage(); } $this->_action_msg = ActionMessages::created($result); } }