@@ -818,15 +818,7 @@ public function api_image( $destfile, $attachment_id, $page )
818
818
if ( ! isset ( $ result ['content ' ] ) || ! isset ( $ result ['content_type ' ] ) || $ result ['content_type ' ] != 'image/jpeg ' )
819
819
throw new Exception ( __ ( "Pdf.Ninja API server did not send an expected response " , 'pdf-forms-for-contact-form-7 ' ) );
820
820
821
- $ handle = @fopen ( $ destfile , 'w ' );
822
-
823
- if ( ! $ handle )
824
- throw new Exception ( __ ( "Failed to open file for writing " , 'pdf-forms-for-contact-form-7 ' ) );
825
-
826
- fwrite ( $ handle , $ result ['content ' ] );
827
- fclose ( $ handle );
828
-
829
- if ( ! file_exists ( $ destfile ) )
821
+ if ( file_put_contents ( $ destfile , $ result ['content ' ] ) === false || ! is_file ( $ destfile ) )
830
822
throw new Exception ( __ ( "Failed to create file " , 'pdf-forms-for-contact-form-7 ' ) );
831
823
832
824
return true ;
@@ -932,15 +924,7 @@ private function api_pdf_helper( $destfile, $endpoint, $attachment_id, $data, $e
932
924
if ( ! isset ( $ result ['content ' ] ) || ! isset ( $ result ['content_type ' ] ) || $ result ['content_type ' ] != 'application/pdf ' )
933
925
throw new Exception ( __ ( "Pdf.Ninja API server did not send an expected response " , 'pdf-forms-for-contact-form-7 ' ) );
934
926
935
- $ handle = @fopen ( $ destfile , 'w ' );
936
-
937
- if ( ! $ handle )
938
- throw new Exception ( __ ( "Failed to open file for writing " , 'pdf-forms-for-contact-form-7 ' ) );
939
-
940
- fwrite ( $ handle , $ result ['content ' ] );
941
- fclose ( $ handle );
942
-
943
- if ( ! file_exists ( $ destfile ) )
927
+ if ( file_put_contents ( $ destfile , $ result ['content ' ] ) === false || ! is_file ( $ destfile ) )
944
928
throw new Exception ( __ ( "Failed to create file " , 'pdf-forms-for-contact-form-7 ' ) );
945
929
946
930
return true ;
0 commit comments