Don't upload file if entry greater than ""?

Discussion in 'PHP' started by mokimofiki, Feb 19, 2010.

  1. #1
    EDIT: Title makes no sense It should say: Upload file if entry does not equal ""

    I am having an issue when creating a form for modifying an entry.

    This is what I have:

    the form:
    echo "<tr><td>Rendering Image:</td><td><input type=\"file\" name=\"rendering\" /></td><td></td></tr>\n";
    Code (markup):

    the upload or using old entry:
    
    $filetomodify = mysql_query("SELECT * FROM homes WHERE modelnumber='$_POST[modelnumber]'");
    $filetomodify = mysql_fetch_array($filetomodify);    
        
    //UPLOAD RENDERING PICTURE IF ONE WAS CHOSEN ELSE USE CURRENT ONE
    if($_FILES['rendering'] != "") {
    $filename1 = "rend-".$_POST['collection'].$_POST['modelnumber']."-".strtolower($_FILES['rendering']['name']);
    move_uploaded_file($_FILES['rendering']['tmp_name'], $_SERVER['DOCUMENT_ROOT']."/homes/".$filename1);
    } else {
    $filename1 = $filetomodify['renderingimg'];
    }
    Code (markup):
    What I need it to do it upload and replace the old entry in the database if you chose a file in the form. If you didn't choose a file and left the rendering image input blank then I want it to just use whatever is already in the database.

    Thank you in advance.
     
    mokimofiki, Feb 19, 2010 IP
  2. mokimofiki

    mokimofiki Well-Known Member

    Messages:
    444
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    130
    #2
    figured it out never mind.

    I was looking for an array to be blank but the value is going to be array unless I specify a name. For anyone running across this thread you fix the above code by replacing.

    if($_FILES['rendering'] != "")

    with:

    if(strtolower($_FILES['rendering']['name']) != "")
     
    mokimofiki, Feb 19, 2010 IP