php - Im having one issue editing my image gallery from my news (Im deleting my images from my folder even when I dont want to edit my images gallery) -
i have table "news" , 1 "gallery".
in table "gallery" have field "news_id", bacause when insert images in gallery table, im inserting images belong news.
i have file "news-create.php", have form asks title, content , have input file select images gallery(this input file optional, no required).
im creating news sucess, our without image gallery, im creating news correctly.
but now, editing news in "news-edit.php", im having 1 problem doing images gallery update.
first, in "news-index.php" have list of news have, , have link in each news when click in each news pass url id of clicked news: , id:
$newsid = $_get['news_id'];
then have if command when form submited:
if(isset($_post['sendform'])){ $f['title'] = $_post['title']; $f['content'] = $_post['content']; }
then have update:
$updnot = $pdo->prepare("update news set title=?, content = ? id_news = ?"); $updnot->bindparam(1,$f['title']); $updnot->bindparam(2,$f['content']); $updnot->bindparam(3,$newsid); $updnot->execute();
then if update homecoming sucess, want verify if field select images gallery selected take images or not.
if not selected , news have images gallery want maintain actual images gallery.
if news dont have images gallery, , in edit form dont select images gallery, dont want insert images.
but if select images gallery, want verify if exists images in gallery, if exists want remove them folder, , want upload folder , update in gallery table new images.
the problem is, when dont select images im entering in if if($_files['gb']['tmp_name'])
, , im removing images folder. , so, when have images gallery in news , in edit news page dont take images gallery, images beingness removed folder, , dont want that.
i want remove images folder, when user in edit news page select new images gallery, , so, first remove images folder relative news beingness edited, , upload , update in gallery table new images.
somebody there can help me solve problem? im here hours , dont find solution this, bcause when if verify if user selected new images, when user dont select images im entering in if, seems have images selected when dont select it...
so, when update homecoming sucess have code:
if($updnot->rowcount() >=1){ if($_files['gb']['tmp_name']){ $readgall = $pdo->prepare("select * gallery news_id = ?"); $readgall->bindparam(1, $nesid); $readgall->execute(); if($readgall->rowcount()>=1){ while ($resultg = $readgall->fetch(pdo::fetch_assoc)){ if(file_exists($path.$resultgall['img']) && !is_dir($path.$resultgall['img'])){ unlink($path.$resultgall['img']); } //here upload , update on gallery table when can prepare problem } } }
you never bothered checking if file uploaded. blindly process upload. if nil uploaded, or upload failed, trash database invalid/incorrect "upload" information.
at bare minimum should have
if($_files['gb']['error'] === upload_err_ok) { ... file uploaded }
php
No comments:
Post a Comment