【发布时间】:2019-06-23 07:55:06
【问题描述】:
在事件表单中,如果没有上传新图像,我会尝试保留(更新)现有图像。表格的其余部分保留位置、时间等信息。 但是,当您在点击更新后尝试使用现有图像(在您点击更新之前确实显示)时,现有图像会消失并且不会将其自身包含在更新中。我是业余爱好者。 ..您的帮助表示赞赏。下面是一些代码:
function eventadd(){
if($_REQUEST['startampm'] == 'PM') $_REQUEST['starthour'] += 12;
$datetimescheduled = $_REQUEST['startyear'].'-'.$_REQUEST['startmonth'].
'-'.$_REQUEST['startdate'].' '.$_REQUEST['starthour'] .
':'.$_REQUEST['startminute'].':00';
$filetmp = $_FILES['file_img']['tmp_name'];
$filename = $_FILES['file_img']['name'];
$filetype = $_FILES['file_img']['type'];
$filepath = "flyers/".$filename;
move_uploaded_file($filetmp,$filepath);
$query = 'insert into eventcalendar '.
'(dateentered,datetimescheduled,title,location,description,img_name,img_path,img_type,soldout,private,free,paydoor,ticketlink,ticketURL) '.
'values '.'(now(),"'.$datetimescheduled.'","'.stripslashes($_REQUEST['title']).'","'.addslashes($_REQUEST['location']).'","'.stripslashes($_REQUEST['description']).'","'.$filename.'","'.$filepath.'","'.$filetype.'","'.addslashes($_REQUEST['soldout']).'","'.addslashes($_REQUEST['private']).'","'.addslashes($_REQUEST['free']).'","'.addslashes($_REQUEST['paydoor']).'","'.addslashes($_REQUEST['ticketlink']).'","'.addslashes($_REQUEST['ticketURL']).'")';
$result = mysql_query($query) or die("Query failed : " . mysql_error());
这里是更新表格,图片没有保留的地方:
// update existing event action
if($updateevent) {
if($startampm == 'PM') $starthour += 12;
$datetimescheduled = $startyear.'-'.$startmonth.'-'.$startdate.' '.$starthour .':'.$startminute.':00';
// added to try to fix update image
$filetmp = $_FILES['file_img']['tmp_name'];
$filename = $_FILES['file_img']['name'];
$filetype = $_FILES['file_img']['type'];
$filepath = "flyers/".$filename;
// end fix - also see image name field didnt work
move_uploaded_file($filetmp,$filepath);
$query = 'update eventcalendar set '.
'datetimescheduled = "'.$datetimescheduled.'",'.
'title = "'.stripslashes($title).'",'.
'location = "'.addslashes($location).'",'.
'description = "'.stripslashes($description).'",'.
'img_name = "'.$filename.'",'.
'img_path = "'.$filepath.'",'.
'img_type = "'.$filetype.'",'.
'soldout = "'.stripslashes($soldout).'",'.
'private = "'.stripslashes($private).'",'.
'free = "'.stripslashes($free).'",'.
'paydoor = "'.stripslashes($paydoor).'",'.
'ticketlink = "'.stripslashes($ticketlink).'",'.
'ticketURL = "'.stripslashes($ticketURL).'"'.
'where id = '.$id;
$result = mysql_query($query) or die("Query failed : " . mysql_error());
HTML 表单摘录:
<td align="right">IMAGE:</td>
<td><input name="file_img" type="file"><?php echo $row['img_path'] ?><?php echo '<img src='. $row['img_path'] .' class="img-responsive no-img thumb-img">'; ?><br>
同样,当提交这个没有新图像的 HTML 表单时,现有图像不会自行更新。
我得到的只是:传单/(没有图像名称)
虽然它显示为:<img src='. $row['img_path'] .
但在点击SUBMIT后不包含自身。
【问题讨论】:
-
是的,这个脚本已经有 10 年的历史了,除了上面的问题之外,它在某个地方找到了它可以工作的地方。而且我确实对自己说,它现在已经过时了。我将修改一个更安全的更现代的脚本。感谢您的确认。 !!