PHP如果没有选择图像,如何使用旧图像

时间:2013-02-02 13:00:49

标签: php file-upload if-statement image-uploading

如果没有选择图像,如何使用旧图像?

当有人更新其个人资料但未选择要更新的图片时,该个人资料页面应该保留旧图像。

应该是这个if-else语句还是会有其他方式?

    //check if file is selected.
    if (empty($_FILES['profilepic']))
    {
                 //if file selected this code should run

         $fileselected="file selected";
    }
    else
    {
                //this executes if file not selected
        $fileselected="No File Has Been Selected";
    }

echo $fileselected;

应如何编码??

2 个答案:

答案 0 :(得分:1)

感谢@Lion

if($_FILES["profilepic"]["error"])
{//if the file is not selected} 
else {//if the file is selected}

对我来说非常有用.. :))

答案 1 :(得分:0)

if(empty($_FILES['image']['name']))
{
    $image=$row['image'];
    //upload from root folder//
    $upload=$_SESSION['KCFINDER']['uploadURL'] = '/images'.$image;
    upload script
} else {
    normal upload script
}