PHP头条
热点:

PHP捕捉异常的有关问题


PHP捕捉错误的问题
先看看代码,很简单就是保存FLASH提交的betys图片数据。


function customError() {  }
set_error_handler("customError");

$destination_folder="face/"; //上传文件路径
$xmlstr =$GLOBALS[HTTP_RAW_POST_DATA];//获取post提交的数据
if(empty($xmlstr)) 
{
$xmlstr = file_get_contents('php://input');//读取post提交数据的另一种方法
}
if(!file_exists($destination_folder))
{
mkdir($destination_folder);//创建存放图片的目录
}
$jpg = $xmlstr;//得到post过来的二进制原始数据
$imgUrl=$destination_folder.time().rand(0, 99).".png";
$file = fopen($imgUrl,"w");//打开文件准备写入
fwrite($file,$jpg);//写入
fclose($file);//关闭

echo 1;


现在无论如何,都会echo 1,
但是如果我想在保存失败的时候返回-1,比如磁盘满、路径错误或者没有定权限等,
要返回错误给flash来告之用户,这个怎么做呢?
php里面的try真是很难用啊
------解决方案--------------------
function customError() {  }
set_error_handler("customError");
 
$destination_folder="face/"; //上传文件路径
$xmlstr =$GLOBALS[HTTP_RAW_POST_DATA];//获取post提交的数据
if(empty($xmlstr)) 
{
    $xmlstr = file_get_contents('php://input');//读取post提交数据的另一种方法
}
if(!file_exists($destination_folder))
{
    mkdir($destination_folder);//创建存放图片的目录
}
$jpg = $xmlstr;//得到post过来的二进制原始数据
$imgUrl=$destination_folder.time().rand(0, 99).".png";
$file = fopen($imgUrl,"w");//打开文件准备写入
if(fwrite($file,$jpg))
{
  echo '1'; //写入成功
}
else
{
  echo '-1';//写入失败
}
fclose($file);//关闭
 

www.phpzy.comtrue/phprm/35195.htmlTechArticlePHP捕捉异常的有关问题 PHP捕捉错误的问题 先看看代码,很简单就是保存FLASH提交的betys图片数据。 functioncustomError(){} set_error_handler("customError"); $destination_folder="face/";//上传文件路径 $xm...

相关文章

PHP之友评论

今天推荐