Below is the code that I have for uploading images to the server, which generates a file name based on 2 entries of the form....

I need to be able to put a "no image" picture in if the user does not upload a photo.... I am submitting the original code along with what I am trying... any help is appreciated...

Thanks

Rob

Original Code


if (isset ($_FILES['fupload'])){

$filename = $_FILES['fupload']['name'];
$filebeg = $_POST['constid'];
$filesec = $_POST['warnum'];
$newfilename = $filebeg."_".$filesec.".jpg";

$_SESSION['newfilename'] = $newfilename;

$source = $_FILES['fupload']['tmp_name'];
$target = "uploads/images/".$newfilename;
move_uploaded_file($source, $target);
}


This should work (I think).... any help?


if (isset ($_FILES['fupload'])){
     if $_FILES['fupload'] = ' ' {
	 $newfilename = "nofile.jpg"
	 }
	 else  
$filename = $_FILES['fupload']['name']; $filebeg = $_POST['constid']; $filesec = $_POST['warnum']; $newfilename = $filebeg."_".$filesec.".jpg"; $_SESSION['newfilename'] = $newfilename; $source = $_FILES['fupload']['tmp_name']; $target = "uploads/images/".$newfilename; move_uploaded_file($source, $target); }

    Your solution is not going to work because you are still trying to call [man]move_uploaded_file[/man] on $_FILES['fupload']['tmp_name'] even though no file has been uploaded.

      I don't think you understand.....

      The code that I posted is not where you specify the file to be uploaded.

      The code is what processes the specified file for upload, as in:

      1) renames the file based on 2 inputted variables on the submit page.

      2) adds the proper filename to the record in the db table.

      3) places the renamed file into the proper directory for recall later...

      The original code works just fine for the upload and rename..... however what I need to do is have the processing figure out if the user did not specify a file for upload. If the user did not upload a image, then I want the system to default to a standard "no image" file, and display that....

      The no image file will be a standard file on the system, so there would be no reason to rename the file, I need to skip the renaming part:

      
      $filename = $_FILES['fupload']['name'];                 // original file name
      $filebeg = $_POST['constid'];                                 // first variable for new name
      $filesec = $_POST['warnum'];                                // second variable for new name
      $newfilename = $filebeg."_".$filesec.".jpg";         // creation of new filename
      
      

      and just have the filename be specified as:

      $newfilename = "nofile.jpg"

      I'm just not sure that the format below is correct:

      if $_FILES['fupload'] = '' {
      $newfilename = "nofile.jpg"
      }
      else

      
      if (isset ($_FILES['fupload'])){
           if $_FILES['fupload'] = ' ' {
      	 $newfilename = "nofile.jpg"
      	 }
      	 else  
      $filename = $_FILES['fupload']['name']; $filebeg = $_POST['constid']; $filesec = $_POST['warnum']; $newfilename = $filebeg."_".$filesec.".jpg"; $_SESSION['newfilename'] = $newfilename; $source = $_FILES['fupload']['tmp_name']; $target = "uploads/images/".$newfilename; move_uploaded_file($source, $target); }
        if(is_array($_FILES['fupload']) && $_FILES['fupload']['error'] == 0)
          echo 'ok';
        else
          echo 'File upload error or no file uploaded';

          Perhaps...

          if(empty($_FILES['fupload']))
          {
             $newfilename = "nofile.jpg";
          }
          else
          {
             $filename = $_FILES['fupload']['name'];
             $filebeg = $_POST['constid'];
             $filesec = $_POST['warnum'];
             $newfilename = $filebeg . "_" . $filesec . ".jpg";
          
             $_SESSION['newfilename'] = $newfilename;
          
             $source = $_FILES['fupload']['tmp_name'];
             $target = "uploads/images/" . $newfilename;
             move_uploaded_file($source, $target);
          }
          
            Write a Reply...