Example #1
0
 public function ajax()
 {
     $result = array();
     $result['success'] = false;
     $result['msg'] = '';
     $avatarpath = ROOT . 'avatar/';
     $userid = $this->admin['aid'];
     if (!is_writable($avatarpath)) {
         $result['msg'] = 'avatar目录不可写!';
         die($this->json->encode($result));
     }
     $file = $_FILES["__avatar1"];
     if (!IsUploadedFile($file['tmp_name'])) {
         $error = '无效的图片文件!';
     }
     $image_size = @getimagesize($file['tmp_name']);
     //看看它是不是图片
     if (!$image_size) {
         $error = '无效的图片文件!';
     }
     if (isset($error)) {
         $result['msg'] = $error;
         die($this->json->encode($result));
     }
     $ext = '.jpg';
     $avatar = $avatarpath . "{$userid}.jpg";
     //头像绝对路径及文件名
     if (!@move_uploaded_file($file['tmp_name'], $avatar)) {
         $result['msg'] = '保存头像文件失败, 请重试!';
         die($this->json->encode($result));
     }
     //返回大头像的URL
     $result['msg'] = SYSDIR . "avatar/{$userid}.jpg?" . time();
     //加一个参数方便更新原头像
     $result['success'] = true;
     die($this->json->encode($result));
 }
 function TestFieldEmpty($s_fld, &$s_mesg)
 {
     global $aFileVars;
     // temporary until code completed
     $s_mesg = "";
     $b_empty = TRUE;
     if (!isset($this->_aFields[$s_fld])) {
         //
         // Each file var is an array with these elements:
         //      "name" => The original name of the file on the client machine.
         //      "type" => The mime type of the file, if the browser provided this information.
         //      "tmp_name" => The temporary filename of the file in which the uploaded file was stored on the server.
         //      "error" => The error code associated with this file upload.
         //                  NOTE: "error" was added in PHP 4.2.0
         //      "size" => The size, in bytes, of the uploaded file.
         //
         // Error codes (the constants are only available from PHP 4.3.0 so
         // we have to use the raw numbers):
         //  UPLOAD_ERR_OK
         //      Value: 0; There is no error, the file uploaded with success.
         //  UPLOAD_ERR_INI_SIZE
         //      Value: 1; The uploaded file exceeds the upload_max_filesize directive in php.ini.
         //  UPLOAD_ERR_FORM_SIZE
         //      Value: 2; The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form.
         //  UPLOAD_ERR_PARTIAL
         //      Value: 3; The uploaded file was only partially uploaded.
         //  UPLOAD_ERR_NO_FILE
         //      Value: 4; No file was uploaded.
         //
         if (FILEUPLOADS) {
             if (IsSetSession("FormSavedFiles")) {
                 $a_saved_files = GetSession("FormSavedFiles");
                 if (isset($a_saved_files[$s_fld])) {
                     $a_upload = $a_saved_files[$s_fld];
                 } elseif (isset($aFileVars[$s_fld])) {
                     $a_upload = $aFileVars[$s_fld];
                 }
             } elseif (isset($aFileVars[$s_fld])) {
                 $a_upload = $aFileVars[$s_fld];
             }
         }
         if (isset($a_upload)) {
             if (isset($a_upload["tmp_name"]) && !empty($a_upload["tmp_name"]) && isset($a_upload["name"]) && !empty($a_upload["name"])) {
                 if (IsUploadedFile($a_upload)) {
                     $b_empty = false;
                 }
             }
             if ($b_empty && isset($a_upload["error"])) {
                 switch ($a_upload["error"]) {
                     case 1:
                         $s_mesg = GetMessage(MSG_FILE_UPLOAD_ERR1);
                         break;
                     case 2:
                         $s_mesg = GetMessage(MSG_FILE_UPLOAD_ERR2);
                         break;
                     case 3:
                         $s_mesg = GetMessage(MSG_FILE_UPLOAD_ERR3);
                         break;
                     case 4:
                         $s_mesg = GetMessage(MSG_FILE_UPLOAD_ERR4);
                         break;
                     case 6:
                         $s_mesg = GetMessage(MSG_FILE_UPLOAD_ERR6);
                         break;
                     case 7:
                         $s_mesg = GetMessage(MSG_FILE_UPLOAD_ERR7);
                         break;
                     case 8:
                         $s_mesg = GetMessage(MSG_FILE_UPLOAD_ERR8);
                         break;
                     default:
                         $s_mesg = GetMessage(MSG_FILE_UPLOAD_ERR_UNK, array("ERRNO" => $a_upload["error"]));
                         break;
                 }
             }
         }
     } else {
         $b_empty = FieldManager::IsEmpty($this->_aFields[$s_fld]);
     }
     return $b_empty;
 }
 function MergeFileArrays($a_new_files, $a_saved_files)
 {
     if (isset($a_saved_files)) {
         foreach ($a_saved_files as $s_key => $a_def) {
             if (isset($a_new_files[$s_key])) {
                 if (!IsUploadedFile($a_new_files[$s_key])) {
                     $a_new_files[$s_key] = $a_def;
                 }
             } else {
                 $a_new_files[$s_key] = $a_def;
             }
         }
     }
     return $a_new_files;
 }
Example #4
0
 function RegisterData($a_form_data, $a_file_vars)
 {
     global $FMCalc;
     foreach ($a_form_data as $s_name => $s_value) {
         if (isset($s_name) && isset($s_value)) {
             if (($s_msg = $FMCalc->RegisterExternalData("PHP", "string", $s_name, "c", $s_value)) !== true) {
                 Error("fmcompute_regdata", GetMessage(MSG_COMP_REG_DATA, array("NAME" => $s_name, "ERROR" => $s_msg)), false, false);
             }
         }
     }
     foreach ($a_file_vars as $s_fld_name => $a_file_spec) {
         if (IsUploadedFile($a_file_spec)) {
             $s_value = $a_file_spec['name'];
         } else {
             $s_value = "";
         }
         if (($s_msg = $FMCalc->RegisterExternalData("PHP", "string", $s_fld_name, "c", $s_value)) !== true) {
             Error("fmcompute_regdata", GetMessage(MSG_COMP_REG_DATA, array("NAME" => $s_fld_name, "ERROR" => $s_msg)), false, false);
         }
     }
 }