예제 #1
0
function uploadPhoto($user, $file)
{
    if ($user->getRole()->getRoleID() == "4") {
        return "This user was forbidden to do this!";
    }
    if (gettype($file["error"]) == "array") {
        return "Only accept one file!";
    }
    $res = isValidUploadFile($file["error"]);
    if ($res !== true) {
        return $res;
    }
    $res = isValidImage($file["name"]);
    if ($res !== true) {
        return $res;
    }
    $fileDir = "photo/";
    $filePath = $fileDir . $user->getUserID() . "." . pathinfo($file["name"], PATHINFO_EXTENSION);
    if (file_exists($filePath)) {
        unlink($filePath);
    }
    if (!move_uploaded_file($file['tmp_name'], $filePath)) {
        return "Fail to move file, please contact administrator!";
    }
    $user->setPhotoURL($filePath);
    return true;
}
예제 #2
0
function uploadFile($userID, $groupID, $file)
{
    $userDAO = new UserDAO();
    $user = $userDAO->getUserByID($userID);
    if ($user->getRole()->getRoleID() == "4") {
        return "This user was forbidden to upload file!";
    }
    if (!isValidID($groupID)) {
        return "Group id is not valid!";
    }
    $groupDAO = new GroupDAO();
    $group = $groupDAO->getGroupByID($groupID);
    if ($group === null) {
        return "Can not find this group!";
    }
    if ($group->getActivateStatus() === "2") {
        return "Group is not activated!";
    }
    $groupMemberDAO = new GroupMemberDAO();
    $groupMember = $groupMemberDAO->getGroupMember($group, $user);
    if ($groupMember === null) {
        return "User didn't belong to this group!";
    }
    if (gettype($file["error"]) == "array") {
        return "Only accept one file!";
    }
    $res = isValidUploadFile($file["error"]);
    if ($res !== true) {
        return $res;
    }
    $fileType = -1;
    $res = isValidImage($file["name"]);
    if ($res === true) {
        $fileType = "2";
    }
    $res = isValidFile($file["name"]);
    if ($res === true) {
        $fileType = "3";
    }
    if ($fileType === -1) {
        return "Only accepts jpeg/jpg/gif/png/zip file!";
    }
    $record = new Record($group, $user, $fileType, "temp", "1");
    $recordDAO = new RecordDAO();
    $recordDAO->insertRecord($record);
    $fileDir = "upload/";
    $filePath = $fileDir . $record->getRecordID() . "_" . $file["name"];
    $record->setContent($filePath);
    $recordDAO->updateRecord($record);
    if (file_exists($filePath)) {
        unlink($filePath);
    }
    if (!move_uploaded_file($file['tmp_name'], $filePath)) {
        return "Fail to move file, please contact administrator!";
    }
    return true;
}
 function RequestFileUpload($_user, $_filename)
 {
     $fileid = md5(namebase($_filename) . $this->UserId . $this->BrowserId);
     $filemask = $this->UserId . "_" . $fileid;
     $fileurid = EX_FILE_UPLOAD_REQUEST . "_" . $fileid;
     $request = new FileUploadRequest($fileurid, $this->DesiredChatPartner);
     $request->SenderUserId = $this->UserId;
     $request->FileName = namebase($_filename);
     $request->FileMask = $filemask;
     $request->FileId = $fileid;
     $request->ChatId = $this->ChatId;
     $request->SenderBrowserId = $this->BrowserId;
     $request->Load();
     if (!$request->FirstCall && !$request->Closed) {
         if ($request->Permission == PERMISSION_FULL) {
             $_user->AddFunctionCall("top.lz_chat_file_start_upload('" . $_filename . "');", false);
         } else {
             if ($request->Permission == PERMISSION_NONE) {
                 $_user->AddFunctionCall("top.lz_chat_file_stop();", false);
                 $_user->AddFunctionCall("top.lz_chat_file_error(1);", false);
                 $request->Close();
             }
         }
     } else {
         $request->FirstCall = true;
         $request->Error = false;
         $request->Closed = false;
         $request->Permission = PERMISSION_VOID;
         if (!isValidUploadFile($_filename)) {
             $_user->AddFunctionCall("top.lz_chat_file_error(2);", false);
         } else {
             $request->Save();
         }
     }
     return $_user;
 }
예제 #4
0
 function AppendPostFile($_postKey, $_userId)
 {
     if (!empty($_FILES[$_postKey]) && true) {
         $filename = namebase($_FILES[$_postKey]['name']);
         if (!isValidUploadFile($filename)) {
             return $filename;
         }
         $fileId = getId(32);
         $fileurid = $_userId . "_" . $fileId;
         if (move_uploaded_file($_FILES[$_postKey]["tmp_name"], PATH_UPLOADS . $fileurid)) {
             processResource("SYSTEM", $fileId, $fileurid, 3, $filename, 0, 100, $_FILES[$_postKey]["size"]);
             $this->ApplyAttachment($fileId);
             return $filename;
         }
     }
 }