thinkphp5 ´óÀ¨ºÅ¹ýʧÔõô½â¾ö
ÔÚʹÓÃthinkphp5¾ÙÐпª·¢Àú³ÌÖУ¬¸÷È˶¼ÓпÉÄÜÓöµ½¹ýÖÖÖÖ¸÷ÑùµÄÎÊÌ⣬ÆäÖÐ×î³£¼ûµÄ¾ÍÊÇÓï·¨¹ýʧ¡£ÆäÖУ¬¹ØÓÚ´úÂë¿é´óÀ¨ºÅµÄʹÓã¬ÓÐʱ¼äÒ²»á·ºÆðһЩСÎÊÌâ¡£±¾ÎĽ«ÖصãÏÈÈÝthinkphp5´óÀ¨ºÅ¹ýʧµÄÇéÐμ°Æä½â¾öÒªÁì¡£
ÎÊÌâÐÎò
ÔÚ¿ª·¢Àú³ÌÖУ¬ÎÒÃÇÓÐʱ¼ä»áÓöµ½ÔÚ´úÂë¿éÍâ»òÄÚȱÉÙ´óÀ¨ºÅµ¼ÖµĹýʧ¡£
ÏÂÃæÊÇÒ»¸öÀý×Ó£º
if($file->validate(['size'=>2048000,'ext'=>'jpg,png,gif'])->move($path)){ return json_encode(['code' => 1, 'msg' => 'ÉÏ´«ÀÖ³É']); } else return json_encode(['code' => 0, 'msg' => 'ÉÏ´«Ê§°Ü']);
µÇ¼ºó¸´ÖÆ µÇ¼ºó¸´ÖÆ
ÔÚÕâ¶Î´úÂëÖУ¬ÓÉÓÚelseÓï¾äȱÉÙ´óÀ¨ºÅ£¬ÏµÍ³ÆÊÎöʱ²»¿É׼ȷʶ±ðÕâ¸öÓï¾ä£¬´Ó¶øµ¼Ö³ÌÐò·ºÆð¹ýʧ¡£
½â¾öÒªÁì
ÔÚ½â¾ö´óÀ¨ºÅ¹ýʧµÄÎÊÌâʱ£¬ÎÒÃÇÖ»ÐèҪȷ±£´úÂë¿éÄÚÍâµÄ´óÀ¨ºÅÊdzɶԷºÆðµÄ¼´¿É¡£¸üÏêϸµÄ½â¾öÒªÁìÈçÏ£º
Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»
1) °ü¹Ü´úÂë¿éÍâµÄ´óÀ¨ºÅ±£´æ
ÔÚÒÔÏ´úÂëÖУº
if($file->validate(['size'=>2048000,'ext'=>'jpg,png,gif'])->move($path)){ return json_encode(['code' => 1, 'msg' => 'ÉÏ´«ÀÖ³É']); } else return json_encode(['code' => 0, 'msg' => 'ÉÏ´«Ê§°Ü']);
µÇ¼ºó¸´ÖÆ µÇ¼ºó¸´ÖÆ
ÎÒÃÇ¿ÉÒÔ½«elseÓï¾äµÄ´óÀ¨ºÅ¼ÓÉÏ£¬¼´¿É×èÖ¹·ºÆð¹ýʧ¡£´úÂëÈçÏ£º
if($file->validate(['size'=>2048000,'ext'=>'jpg,png,gif'])->move($path)){ return json_encode(['code' => 1, 'msg' => 'ÉÏ´«ÀÖ³É']); } else { return json_encode(['code' => 0, 'msg' => 'ÉÏ´«Ê§°Ü']); }
µÇ¼ºó¸´ÖÆ
2) °ü¹Ü´úÂë¿éÄڵĴóÀ¨ºÅ±£´æ
ÔÚÒÔÏ´úÂëÖУº
$data = [ ['id' => 1, 'name' => 'СÃ÷'], ['id' => 2, 'name' => 'Сºì'], ['id' => 3, 'name' => 'С¸Õ'] ] foreach($data as $val) $name = $val['name']; echo $name;
µÇ¼ºó¸´ÖÆ
ÎÒÃÇ¿ÉÒÔÔÚforeachÓï¾äÖеĴúÂë¿é¼ÓÉÏ´óÀ¨ºÅ£¬¼´¿É×èÖ¹·ºÆð¹ýʧ¡£´úÂëÈçÏ£º
$data = [ ['id' => 1, 'name' => 'СÃ÷'], ['id' => 2, 'name' => 'Сºì'], ['id' => 3, 'name' => 'С¸Õ'] ] foreach($data as $val) { $name = $val['name']; echo $name; }
µÇ¼ºó¸´ÖÆ
×ܽá
ÔÚʹÓÃThinkPHP5±àд´úÂëÀú³ÌÖУ¬·ºÆðÓï·¨¹ýʧµÄÇéÐÎÊDz»¿É×èÖ¹µÄ¡£ÔÚ´¦Àí´óÀ¨ºÅ¹ýʧʱ£¬ÎÒÃÇÖ»ÐèҪƾ֤ÉÏÊö½â¾öÒªÁì°ü¹Ü´úÂë¿éÄÚÍâµÄ´óÀ¨ºÅ³É¶Ô·ºÆ𣬼´¿ÉÓÐÓÃ×èÖ¹·ºÆð¹ýʧ¡£
ÒÔÉϾÍÊÇthinkphp5 ´óÀ¨ºÅ¹ýʧÔõô½â¾öµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡