0

i have 2 fields on my project to upload documents(pdf, words) i use the following code to get the file extension on upload and rename the file with my custom name:

$ext= pathinfo($rsnew["File"], PATHINFO_EXTENSION);

my problem that i need to add to this code that, if one of the field if not update with a new document then it use the current extension of the oldrecord that was previous upload, and no change to blank extension

any idea, thanks in advance

using this code but no working

$ext= pathinfo($rsnew["File"], PATHINFO_EXTENSION);
$ext2= pathinfo($rsold["File"], PATHINFO_EXTENSION);
 // $trim = substr($docpath,0,4);// not using now

if($_FILES["File"]["size"]  == 0) {
 $rsnew["File"] = "$rname $docpath1 $docpath2 " . " " . "$docpath ID$randomNumber" . ".$ext2";

    
} else {
  $rnew["File"] = "$rname $docpath1 $docpath2 " . " " . "$docpath ID$randomNumber" . ".$ext";
    return TRUE;
}

}
Mike 'Pomax' Kamermans
  • 49,297
  • 16
  • 112
  • 153
Christ2000
  • 21
  • 4
  • You should check the `error` entry in the $_FILES array, https://www.php.net/manual/en/features.file-upload.errors.php - if the user did not select any file before submitting the form, then that will contain the value of UPLOAD_ERR_NO_FILE. – CBroe Sep 14 '21 at 07:02
  • also, don't trust extensions: verify that they are what they claim to be, otherwise someone can just upload an .exe with a pdf extension, and get your server to host their executable. – Mike 'Pomax' Kamermans Sep 21 '21 at 01:03

0 Answers0