Hi guys,

I have a form that allows five photo uploads at once. The thing is when the user uploads only one photo that should be it... but it still tries to upload and move the other, non existent photos. I have an if statement that does not seem to be working.... here it is:

<?php
//IF THERE IS A FIFTH PICTURE
if (isset($_FILES['articlePicFive']) || $_FILES['articlePicFive'] != NULL || $_FILES['articlePicFive'] != '') {
$imageName = $gathered['articleId'];
// PROCESS IMAGE
$target_path = "../images/articles/";
$target_path = $target_path . basename( $_FILES['articlePicFive']['tmp_name']); 
$_FILES['articlePicFive']['tmp_name'];

//MOVE THE IMAGE TO THUMBNAILS
move_uploaded_file($_FILES['articlePicFive']['tmp_name'], $target_path);

//EXPLODE TO RENAME IMAGE
$fileName = $_FILES['articlePicFive']['name'];
$broken = explode(".", $fileName);
rename("../images/articles/".basename($_FILES['articlePicFive']['tmp_name'])."", "../images/articles/".$imageName."_05." .$broken[1]."");

$update = mysql_query("UPDATE articles SET articlePicFive='" .$imageName."_05." .$broken[1]. "' WHERE articleId='".$imageName."'"		) or die(mysql_error());
}
?>

What am I doing wrong? See if statement at the start... even though the form fiels is empty it is treating it as there is a file...

Thanks

    if (is_uploaded_file($_FILES['articlePicFive']['tmp_name'])) {
       // this file has been uploaded
    }
    else
    {
       // not uploaded
    }
    

      Try

      echo "<pre>";
      print_r($_FILES);
      echo "</pre>";

      $_FILES['articlePicFive'] should still be an array, not a string, so isset, != NULL, and !="" won't work

      Also,
      Check your <form> tag, do you have this:

      enctype="multipart/form-data"

      ?

      http://www.php.net/features.file-upload

      Note: Be sure your file upload form has attribute enctype="multipart/form-data" otherwise the file upload will not work.

        Write a Reply...