PHP catch exceptions

Source: Internet
Author: User
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
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.