PHPExcel checks if a file is saved

I am using PHPExcel . I am trying to save a file in a directory (File is being saved). Can I confirm that the file is saved? We use $writer->save($filename);to save the file.
I tried both

if( $writer->save($filename) ){
    echo "File successfully saved";
}

As well as

 if( $writer->save($filename) === true){
    echo "File successfully saved";
 }

Can anyone help? Thanks in advance.!

+4
source share
2 answers

PHPExcel throws exceptions if it fails; therefore the try / catch block

try {
    $writer->save($filename);
    echo "File successfully saved";
} catch (Exception $e) {
    echo 'ERROR: ', $e->getMessage();
    die();
}
+5
source

It only shows if a problem has occurred. This will not show a message for the file saved.

try {
    $writer->save($filename);
    echo "File successfully saved";
} catch (Exception $e) {
    echo 'ERROR: ', $e->getMessage();
    die();
}

I want to display a success message.

0
source

Source: https://habr.com/ru/post/1628754/


All Articles