您不必將文件移動到另一個文件夾。不要緊,他們住,只要申請就可以找到它們在那裏(見:path
)。
什麼是對你有DB計劃?你顯示模式,但提到你不知道如何使用它?
反正......如果你增加了一個active
場畫廊表,然後你可以將其標記在提交的活躍。
gallery
id_gallery int
name text
description text
date_created date
active default 0
gallery_images
id_image int
gallery_id int
path text
前提是你實例,當第一圖像上傳畫廊(或在某點)和行插入gallery_images對於上載的每個圖像,你可以提交像這樣:
function submit_gallery($id = NULL, $active = NULL)
{
if($id AND $active === 1)
{
$this->db->where('id', $id);
$this->db->update('gallery', array('active' => 1));
}
//could have a "cancel" button call this. or use a cron job
elseif($id AND $active === 0)
{
$this->db->where('gallery_id', $id);
$imgs = $this->db->get('gallery_images');
foreach($imgs->result() as $img)
{
//delete the img files
unlink($img->path);
}
$this->db->where('gallery_id', $id);
$this->db->delete('gallery_images');
}
}
這種方法在第一次圖片上傳時創建圖庫,但在我的情況下,用戶首先上傳圖片(拖放它們),然後(在編寫關於圖庫的數據之後),他點擊**創建圖庫**。這樣圖像在圖像被創建之前就被上傳了。目前我正在試驗另一張臨時包含圖像的表格,並且在創建圖庫時,該表格中的數據將被複制到** gallery_images **並從臨時表格中刪除。 – Sasha 2013-03-25 18:11:57