PHP capture errors first look at the code. it is very simple to save the betys image data submitted by FLASH. Function & nbsp; customError () & nbsp ;{& nbsp; & nbsp ;}set_error_handler ("customError"); $ destination_folde PHP catch errors
First look at the code, it is very easy to save the betys image data submitted by FLASH.
Function customError (){}
Set_error_handler ("customError ");
$ Destination_folder = "face/"; // file Upload path
$ Xmlstr = $ GLOBALS [HTTP_RAW_POST_DATA]; // obtain the data submitted by post.
If (empty ($ xmlstr ))
{
$ Xmlstr = file_get_contents ('php: // input'); // Another method for reading post-submitted data
}
If (! File_exists ($ destination_folder ))
{
Mkdir ($ destination_folder); // create a directory for storing images
}
$ Jpg = $ xmlstr; // Get the binary raw data after post
$ ImgUrl = $ destination_folder.time (). rand (0, 99). ". png ";
$ File = fopen ($ imgUrl, "w"); // open the file to prepare for writing
Fwrite ($ file, $ jpg); // write
Fclose ($ file); // Close
Echo 1;
Echo 1,
However, if I want to return-1 when the storage fails, such as full disk, wrong path, or no permission,
If an error is returned to the flash user, how can this problem be solved?
Try in php is really difficult to use.
------ Solution --------------------
Function customError (){}
Set_error_handler ("customError ");
$ Destination_folder = "face/"; // file Upload path
$ Xmlstr = $ GLOBALS [HTTP_RAW_POST_DATA]; // obtain the data submitted by post.
If (empty ($ xmlstr ))
{
$ Xmlstr = file_get_contents ('php: // input'); // Another method for reading post-submitted data
}
If (! File_exists ($ destination_folder ))
{
Mkdir ($ destination_folder); // create a directory for storing images
}
$ Jpg = $ xmlstr; // Get the binary raw data after post
$ ImgUrl = $ destination_folder.time (). rand (0, 99). ". png ";
$ File = fopen ($ imgUrl, "w"); // open the file to prepare for writing
If (fwrite ($ file, $ jpg ))
{
Echo '1'; // write successful
}
Else
{
Echo '-1'; // write failed
}
Fclose ($ file); // Close