php - file_put_contents does not return a value -
I have trouble using file_put_contents I thought I could do something like this in Laval / PHP.
$ response = new stdClass (); $ Key = generating (); // a 32 bit key generates $ dir = "/ mnt / my-usb"; If (file_put_contents ($ dir. "/". "Key", $ key) === true) {$ response-> Status = "failed"; $ Response- & gt; Message = "Some user messages that describe the error have to face"; Return Feedback: Jason ($ reaction, 500); }
So I thought I could check status code file_put_contents and return a good error message. However, when I take the step through this code, once it makes a statement, if there is a failure, then it never goes into the statement if I am not sure why I have it withouth === Have tried the truth and I get the same results. I think file_put_contents will return some type of error code that I can see and create a user facing the message, but it comes back automatically and I can not create a response to send the client back any idea? Thanks in advance.
Check the manual:
This function returns the number of bytes The file that was written in, or the wrong on the failure
Meaning: file_put_contents
will never return TRUE
this false
However, if you were urging to use the Boolean value, then you will need to use it:
if (file_put_contents ($ dir. "/" "Key, $ Key)! == incorrect) {// reset code}
In addition to this, there are many examples of how to create file_put_contents
"quietly die" ( That means checking that if the file exists, then the folder Writeable, etc. can be opened for investigation)
Comments
Post a Comment