PHP图像替换? [英] PHP image replacement?
问题描述
我正在导入数据来自数据库的URL,例如 www.mysite.com/images/image1.jpg
设置为变量 newimage1
这是从数据库加载并放在页面上的。
由于这是一个编辑页面,用户可以上传一个新的图片。
如果用户没有上传新图片,但保存了页面,变量 newimage1
没有设置,因为变量被设置为,所以它清除了数据库中现有的图片url。
最好的办法是什么? if语句检查 newimage1
是否为空,并将其从更新数据库中删除?
对不起,这个简单的问题!
$ image_name =;
if(!empty($ _ FILES)){
$ image_name = $ _FILES ['image'] ['tmp_name'];
$ sql =UPDATE table SET var1 ='value1',var2 ='value2';
if($ image_name!=)
$ sql。=,image_name ='。$ image_name。';
$ sql。=WHERE id_entry = 5;
I'm having a brain dead moment... If someone could talk this through with me and make suggestions that'd be great.
I'm importing a URL from a database, eg www.mysite.com/images/image1.jpg
set as variable newimage1
This is loaded from the DB and placed on the page.
As this is an edit page, the user can upload a new image.
If the user doesn't upload a new image, but saves the page anyway, the variable newimage1
is not set, it clears the existing image url from the database because the variable is set to ""
.
What's the best way to do this? An if statement, that checks if newimage1
is blank and removes it from the update to the database?
Sorry for this simple question!
$image_name = "";
if(!empty($_FILES)){
$image_name = $_FILES['image']['tmp_name'];
}
$sql = "UPDATE table SET var1 = 'value1', var2='value2'";
if($image_name != "")
$sql .= ", image_name = '".$image_name."'";
$sql .= " WHERE id_entry = 5";
这篇关于PHP图像替换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!