/** * Store a newly created resource in storage. * * @return Response */ public function store() { $att = new Attachment(); $att->unguard(); $att->fill(Input::only('title', 'description', 'hash', 'hash_algorithm', 'public')); if (!Input::hasFile('upload')) { Session::flash('message', ['content' => 'Geen bestand ontvangen.', 'class' => 'danger']); return View::make('attachments.create', ['attachment' => $att]); } if (!Input::file('upload')->isValid()) { Session::flash('message', ['content' => 'Ongeldig bestand ontvangen.', 'class' => 'danger']); return View::make('attachments.create', ['attachment' => $att]); } $file = Input::file('upload'); $name = $file->getClientOriginalName(); $extension = $file->getClientOriginalExtension(); $att->user_id = Auth::user()->id; $att->filename = $name; $att->extension = $extension; // We need to validate the attributes before moving the attachment into place if (!$att->validate()) { return View::make('attachments.create', ['attachment' => $att])->withErrors($att->validator()); } $file->move($att->folderPath(), $att->filename); $att->path = $att->folderPath(); $att->filesize = filesize($att->fullPath()); if (in_array($att->extension, Attachment::$image_extensions)) { $att->type = 'Image'; } $att->save(); return Redirect::to(route('attachments.show', [$att->id]))->with('message', ['content' => 'Bestand met succes geupload!', 'class' => 'success']); }
public function store($notebookId, $noteId, $versionId) { $note = self::getNote($notebookId, $noteId, $versionId); if ($note->pivot->umask < PaperworkHelpers::UMASK_READWRITE) { return PaperworkHelpers::apiResponse(PaperworkHelpers::STATUS_ERROR, array('message' => 'Permission Error')); } if (Input::hasFile('file') && Input::file('file')->isValid() || Input::json() != null && Input::json() != "") { $fileUpload = null; $newAttachment = null; if (Input::hasFile('file')) { $fileUpload = Input::file('file'); $newAttachment = new Attachment(array('filename' => $fileUpload->getClientOriginalName(), 'fileextension' => $fileUpload->getClientOriginalExtension(), 'mimetype' => $fileUpload->getMimeType(), 'filesize' => $fileUpload->getSize())); } else { $fileUploadJson = Input::json(); $fileUpload = base64_decode($fileUploadJson->get('file')); $newAttachment = new Attachment(array('filename' => $fileUploadJson->get('clientOriginalName'), 'fileextension' => $fileUploadJson->get('clientOriginalExtension'), 'mimetype' => $fileUploadJson->get('mimeType'), 'filesize' => count($fileUpload))); } $newAttachment->save(); // Move file to (default) /app/storage/attachments/$newAttachment->id/$newAttachment->filename $destinationFolder = Config::get('paperwork.attachmentsDirectory') . '/' . $newAttachment->id; if (!File::makeDirectory($destinationFolder, 0700)) { $newAttachment->delete(); return PaperworkHelpers::apiResponse(PaperworkHelpers::STATUS_ERROR, array('message' => 'Internal Error')); } // Get Version with versionId //$note = self::getNote($notebookId, $noteId, $versionId); $tmp = $note ? $note->version()->first() : null; $version = null; if (is_null($tmp)) { $newAttachment->delete(); File::deleteDirectory($destinationFolder); return PaperworkHelpers::apiResponse(PaperworkHelpers::STATUS_NOTFOUND, array('message' => 'version->first')); } while (!is_null($tmp)) { if ($tmp->id == $versionId || $versionId == 0) { $version = $tmp; break; } $tmp = $tmp->previous()->first(); } if (is_null($version)) { $newAttachment->delete(); File::deleteDirectory($destinationFolder); return PaperworkHelpers::apiResponse(PaperworkHelpers::STATUS_NOTFOUND, array('message' => 'version')); } if (Input::hasFile('file')) { $fileUpload->move($destinationFolder, $fileUpload->getClientOriginalName()); } else { file_put_contents($destinationFolder . '/' . $fileUploadJson->get('clientOriginalName'), $fileUpload); } $version->attachments()->attach($newAttachment); // Let's push that parsing job, which analyzes the document, converts it if needed and parses the crap out of it. Queue::push('DocumentParserWorker', array('user_id' => Auth::user()->id, 'document_id' => $newAttachment->id)); return PaperworkHelpers::apiResponse(PaperworkHelpers::STATUS_SUCCESS, $newAttachment); } else { return PaperworkHelpers::apiResponse(PaperworkHelpers::STATUS_ERROR, array('message' => 'Invalid input')); } }
/** * Create Attachment instance and move file to attachmentsDirectory * * @param $data * @param $fileName * @param string $mime * @return \Attachment * @throws \Exception */ protected function createAttachment($data, $fileName, $mime = '') { if (empty($mime)) { $f = finfo_open(); $mime = finfo_buffer($f, $data, FILEINFO_MIME_TYPE); } $newAttachment = new \Attachment(array('filename' => $fileName, 'fileextension' => pathinfo($fileName, PATHINFO_EXTENSION), 'mimetype' => $mime, 'filesize' => strlen($data))); $newAttachment->save(); $destinationFolder = \Config::get('paperwork.attachmentsDirectory') . '/' . $newAttachment->id; if (!\File::makeDirectory($destinationFolder, 0700)) { $newAttachment->delete(); throw new \Exception('Error creating directory'); } file_put_contents($destinationFolder . '/' . $fileName, $data); return $newAttachment; }
/** * Show and process edit attachment form * * @param void * @return null */ function edit() { $this->wireframe->print_button = false; if ($this->active_attachment->isNew()) { $this->httpError(HTTP_ERR_NOT_FOUND); } // if $parent = $this->active_attachment->getParent(); if (!instance_of($parent, 'ProjectObject')) { $this->httpError(HTTP_ERR_NOT_FOUND); } // if $attachment_data = $this->request->post('attachment'); if (!is_array($attachment_data)) { $attachment_data = array('name' => $this->active_attachment->getName()); } // if $this->smarty->assign('attachment_data', $attachment_data); if ($this->request->isSubmitted()) { db_begin_work(); $old_name = $this->active_attachment->getName(); $this->active_attachment->setName(array_var($attachment_data, 'name')); $save = $this->active_attachment->save(); if ($save && !is_error($save)) { db_commit(); $this->active_attachment->ready(); if ($this->request->getFormat() == FORMAT_HTML) { flash_success('File :filename has been updated', array('filename' => $old_name)); $this->redirectToUrl($parent->getViewUrl()); } else { $this->serveData($this->active_attachment); } // if } else { db_rollback(); if ($this->request->getFormat() == FORMAT_HTML) { flash_error('Failed to update :filename', array('filename' => $old_name)); $this->redirectToUrl($parent->getViewUrl()); } else { $this->serveData($save); } // if } // if } // if }
public function actionRepairUpload() { $index = $this->request->getParam("selectedIndex"); $pre_id = $this->request->getParam("upload_save_to_db_id"); $inputFileName = "repair_attached_file" . $index; $attach = CUploadedFile::getInstanceByName($inputFileName); $retValue = ""; if ($attach == null) { $retValue = "提示:不能上传空文件。"; } else { if ($attach->size > 2000000) { $retValue = "提示:文件大小不能超过2M。"; } else { $retValue = '恭喜,上传成功!'; if ($pre_id == 0) { $f = file_get_contents($attach->tempName); $a = new Attachment(); $a->ref_type = "failParts"; $a->data = $f; $a->file_path = $attach->name; $a->save(); $cur_id = $a->id; } else { $trans = Yii::app()->db->beginTransaction(); try { $f = file_get_contents($attach->tempName); $a = new Attachment(); $a->ref_type = "failParts"; $a->data = $f; $a->file_path = $attach->name; $a->save(); $cur_id = $a->id; $pre = Attachment::model()->findByPk($pre_id); $pre->delete(); $trans->commit(); } catch (Exception $e) { $retValue = $e->getMessage(); $cur_id = 0; $trans->rollback(); } } echo "<script type='text/javascript'>window.top.window.successUpload('{$retValue}',{$cur_id},{$index})</script>"; exit; } } echo "<script type='text/javascript'>window.top.window.stopUpload('{$retValue}',{$index})</script>"; }
//if attachmentID is sent then this is an update if (isset($_POST['attachmentID']) && $_POST['attachmentID'] != "") { $attachment = new Attachment(new NamedArguments(array('primaryKey' => $_POST['attachmentID']))); } else { $attachment = new Attachment(); $attachment->attachmentID = ''; } if (isset($_POST['sentDate']) && $_POST['sentDate'] != "") { $attachment->sentDate = date("Y-m-d", strtotime($_POST['sentDate'])); } else { $attachment->sentDate = ""; } $attachment->attachmentText = $_POST['attachmentText']; $attachment->licenseID = $_POST['licenseID']; try { $attachment->save(); echo $attachment->primaryKey; } catch (Exception $e) { echo $e->getMessage(); } break; //adding the attachment file to the db - saves the URL to it only //adding the attachment file to the db - saves the URL to it only case 'addAttachmentFile': $attachmentFile = new AttachmentFile(); $attachmentFile->attachmentID = $_GET['attachmentID']; $attachmentFile->attachmentURL = $_GET['attachmentURL']; try { $attachmentFile->save(); echo $attachmentFile->primaryKey; } catch (Exception $e) {
public function postCreate() { // $academy_id = Session::get('school_id_session'); $academy_id = Cookie::get('school_id_session'); if ($academy_id == NULL) { return Redirect::to('/task/create/step-3')->with('message', 'no-school'); } $sTask = Session::get('task'); $task = new Task(); $task->user_id = Auth::user()->id; // $task->type = Session::get('type'); // $task->title = Session::get('title'); // $task->detail = Session::get('detail'); // $task->category_id = Session::get('category_id'); $task->type = $sTask['type']; $task->title = $sTask['title']; $task->detail = $sTask['detail']; $task->category_id = $sTask['category_id']; if ($sTask['type'] == 1) { // $task->amount = Session::get('amount'); $task->amount = $sTask['amount']; $task->totalAmount = $sTask['totalAmount']; } else { if ($sTask['type'] == 2) { // $task->amountStart = Session::get('amountStart'); // $task->amountEnd = Session::get('amountEnd'); if (isset($sTask['amountStart'])) { $task->amountStart = $sTask['amountStart']; $task->amountEnd = $sTask['amountEnd']; } else { $task->amount = $sTask['amount']; } } } // $task->amount = Session::get('amount'); // $task->expiration = Session::get('expiration'); $task->expiration = $sTask['expiration']; $task->state = 1; $task->place = $academy_id; $task->save(); $credit = Auth::user()->credit; // dd($task->category_id); User::where('id', Auth::user()->id)->update(['credit' => $credit - 50]); if (Session::get('hire') != NULL) { $hired_user = User::where('id', Session::get('hire'))->first(); $message = new Message(); $message->from_user_id = Auth::user()->id; $message->to_user_id = $hired_user->id; $message->message = "Can you help me do this task " . "<a class='message-task-title' target='blank' href=\"/task/{$task->id}\">{$task->title}</a> ?"; $message->save(); } if (Session::has('file_name') && Session::get('file_name') != "") { // dd(Session::get('file_name')); $attachment = new Attachment(); $attachment->file_name = Session::get('file_name'); $attachment->task_id = $task->id; $attachment->save(); $attachment->file_hash = md5($attachment->id . $attachment->created_at . $attachment->file_name . $attachment->task_id); $attachment->file_ext = Util::getExtension($attachment->file_name); $attachment->save(); // Session::set('file_hash', $attachment->file_hash); if (!file_exists(public_path() . '/file/' . Auth::user()->id . '/')) { mkdir(public_path() . '/file/' . Auth::user()->id . '/'); } if ($attachment->file_ext == "") { copy(public_path() . '/upload/cache/' . $attachment->file_name, public_path() . '/file/' . Auth::user()->id . '/' . $attachment->file_hash); } else { copy(public_path() . '/upload/cache/' . $attachment->file_name, public_path() . '/file/' . Auth::user()->id . '/' . $attachment->file_hash . '.' . $attachment->file_ext); } } // if (Session::has('images')) { // if (!file_exists(public_path() . '/file/' . Auth::user()->id . '/')) { // mkdir(public_path() . '/file/' . Auth::user()->id . '/'); // } // $images = Session::get('images'); // foreach ($images as $imageName) { // $oldName = public_path() . '/upload/cache/' . Auth::user()->id . '/' . $imageName; // $newName = public_path() . '/file/' . Auth::user()->id . '/' .$imageName; // rename($oldName, $newName); // $image = new Image; // $image->user_id = Auth::user()->id; // $image->task_id = $task->id; // $image->file_name = $imageName; // $image->save(); // } // } Session::forget('title'); Session::forget('detail'); Session::forget('amount'); Session::forget('expiration'); Session::forget('hire'); Session::forget('file_name'); // return Redirect::to('task/list'); return Redirect::to("/school/{$academy_id}"); // return Redirect::to('/'); }
public static function UploadFile($objFile) { $objAttachment = new Attachment(); $objAttachment->creDate = MFBDateTime::Now(); $objAttachment->save(); $arrFileData = pathinfo($objFile['name']); //die(print_r($arrFileData)); $strExtension = $arrFileData['extension']; $strFileName = $objAttachment->idAttachment . '.' . $strExtension; $strNewPath = __UPLOADS_DIR__ . '/' . $strFileName; move_uploaded_file($objFile["tmp_name"], $strNewPath); $objAttachment->fileLoc = $strFileName; $objAttachment->save(); return $objAttachment; }
/** * Metodo para subir un archivo al servidor y guardarlo en la base de datos * @param _FILE $file archivo que se esta subiendo * @param Attachment Entidad con toda la informacion de un archivo a guardar * @return JSON respuesta del proceso de carga de archivo */ public static function uploadAttachmentIntoDB($file, $attachment = '') { $att = $attachment; if (!$att) { $att = new Attachment(); } $f = $file; if ($f) { $att->name = $f->getClientOriginalName(); $att->mime = $f->getMimeType(); $att->size = $f->getSize(); $attfile = file_get_contents($f->getRealPath()); if ($att->encode == 'base64') { $attfile = base64_encode(file_get_contents($f->getRealPath())); } $att->file = $attfile; $att->save(); return Response::json(array('valid' => true)); } else { return Response::json(array('valid' => false, 'error' => array($f->getError(), $f->getErrorMessage()))); } }
/** * Save this object into the database * * @param void * @return boolean * @throws DBQueryError * @throws ValidationErrors */ function save() { $is_new = $this->isNew(); $modified_fields = $this->modified_fields; $old_values = $this->old_values; if ($is_new) { $this->setType(get_class($this)); } // if if ($this->isModified()) { $this->setVersion($this->getVersion() + 1); // increment object version on save... } // if db_begin_work(); $save = parent::save(); if (!$save || is_error($save)) { db_rollback(); return $save; } // if // Log activities... if ($this->log_activities) { if ($is_new) { if ($this->log_creation) { if (instance_of($this, 'File')) { $activity_log = new NewFileActivityLog(); } else { $activity_log = new ObjectCreatedActivityLog(); } // if $activity_log->log($this, $this->getCreatedBy()); } // if } else { if ($this->log_update || $this->log_move_to_trash || $this->log_restore_from_trash) { $trashed = false; $restored = false; if (is_array($this->modified_fields) && in_array('state', $modified_fields)) { if (isset($old_values['state']) && $old_values['state'] == STATE_DELETED && $this->getState() == STATE_VISIBLE) { $restored = true; } // if if (isset($old_values['state']) && $old_values['state'] == STATE_VISIBLE && $this->getState() == STATE_DELETED) { $trashed = true; } // if } // if if ($trashed) { if ($this->log_move_to_trash) { $activity_log = new ObjectTrashedActivityLog(); $activity_log->log($this); } // if } elseif ($restored) { if ($this->log_restore_from_trash) { $activity_log = new ObjectRestoredActivityLog(); $activity_log->log($this); } // if } else { if ($this->log_update) { $activity_log = new ObjectUpdatedActivityLog(); $activity_log->log($this); } // if } // if } // if } // if } // if // Pending files if ($this->can_have_attachments && is_foreachable($this->pending_files)) { foreach ($this->pending_files as $pending_file) { $attachment = new Attachment(); $attachment->setParent($this); if (isset($pending_file['created_by']) && (instance_of($pending_file['created_by'], 'User') || instance_of($pending_file['created_by'], 'AnonymousUser'))) { $attachment->setCreatedBy($pending_file['created_by']); } else { $attachment->setCreatedBy($this->getCreatedBy()); } // if $attachment->setName($pending_file['name']); $attachment->setLocation(substr($pending_file['location'], strlen(UPLOAD_PATH) + 1)); $attachment->setMimeType($pending_file['type']); $attachment->setSize($pending_file['size']); if (instance_of($this, 'File')) { $attachment->setAttachmentType(ATTACHMENT_TYPE_FILE_REVISION); } // if $save_attachment = $attachment->save(); if (is_error($save_attachment)) { db_rollback(); return $save_attachment; } // if } // foreach $this->pending_files = array(); // no more pending files } // if // Set assignees if ($this->can_have_assignees && $this->new_assignees !== false) { $this->old_assignees = $is_new ? array(array(), 0) : Assignments::findAssignmentDataByObject($this); //BOF: mod list($old_subscribers, ) = $this->old_assignees; if (count($old_subscribers)) { foreach ($old_subscribers as $old_subscriber_id) { Subscriptions::unsubscribe(new User($old_subscriber_id), $this); } } //EOF: mod Assignments::deleteByObject($this); $object_id = $this->getId(); if (is_array($this->new_assignees)) { list($assignees, $owner_id) = $this->new_assignees; if (is_foreachable($assignees)) { $user_ids = array(); $to_insert = array(); foreach ($assignees as $user_id) { if (in_array($user_id, $user_ids)) { continue; } // if $is_owner = $user_id == $owner_id ? 1 : 0; $to_insert[] = "({$user_id}, {$object_id}, {$is_owner})"; $user_ids[] = $user_id; } // foreach // Insert assignments $insert = db_execute('INSERT INTO ' . TABLE_PREFIX . 'assignments VALUES ' . implode(', ', $to_insert)); if (is_error($insert) && !$insert) { db_rollback(); return $insert; } // if // Not array... Empty... } else { $assignees = array(); $owner_id = 0; } // if // Clean up assignments cache clean_assignments_cache(); // Make sure that all assignees are subscribed Subscriptions::subscribeUsers($assignees, $this, false); // Check if object is reassigned if (!$is_new) { $reassigned = false; if (is_array($this->old_assignees)) { list($old_assignees, $old_owner_id) = $this->old_assignees; } else { $old_assignees = array(); $old_owner_id = 0; } // if if ($owner_id != $old_owner_id) { $reassigned = true; } else { if (count($assignees) != count($old_assignees)) { $reassigned = true; } else { foreach ($assignees as $assignee_id) { if (!in_array($assignee_id, $old_assignees)) { $reassigned = true; } // if } // foerach } // if } // if if ($reassigned) { event_trigger('on_project_object_reassigned', array(&$this, $this->old_assignees, array($assignees, $owner_id))); } else { $this->old_assignees = false; } // if } // if } // if $this->new_assignees = false; // reset } // if // Search index if (is_foreachable($this->searchable_fields)) { $update_search_index = false; // Do we need to update search index? foreach ($this->searchable_fields as $field) { if (in_array($field, $modified_fields)) { $update_search_index = true; break; } // if } // foreach // We do... Prepare and if content is empty remove it from the index if ($update_search_index) { $content = ''; foreach ($this->searchable_fields as $field) { $value = $this->getFieldValue($field); if ($value) { $content .= $value . "\n\n"; } // if } // foreach if ($content) { search_index_set($this->getId(), 'ProjectObject', $content); } else { search_index_remove($this->getId(), 'ProjectObject'); } // if } // if } // if // Update properties of child elements if (!$is_new) { $properties = array(); if (in_array('visibility', $modified_fields)) { $properties['setVisibility'] = $this->getVisibility(); } // if if (in_array('milestone_id', $modified_fields)) { $properties['setMilestoneId'] = $this->getMilestoneId(); } // if $types = array(); if ($this->can_have_comments) { $types[] = 'Comment'; } // if if ($this->can_have_tasks) { $types[] = 'Task'; } // if if ($this->getHasTime()) { $types[] = 'TimeRecord'; } // if ProjectObjects::updatePropertiesByParent($this, $properties, $types); } // if if (!$is_new && in_array('project_id', $modified_fields)) { ActivityLogs::updateProjectIdCache($this); } // if // Commit and done! db_commit(); return true; }
/** * Provides logic for image picker dialog * * @param void * @return null */ function image_picker() { $project_id = $this->request->get('project_id'); if ($project_id) { $this->active_project = Projects::findById($project_id); } // if if (!instance_of($this->active_project, 'Project')) { $this->active_project = new Project(); } // if $image_picker_url = assemble_url('image_picker', array('project_id' => $this->active_project->getId())); $this->smarty->assign(array('image_picker_url' => $image_picker_url, 'disable_upload' => (bool) $this->request->get('disable_upload'))); if ($this->request->isSubmitted()) { $action = $this->request->post('widget_action'); switch ($action) { case 'upload': // check if any file is uploaded $uploaded_file = array_var($_FILES, 'image', null); if (!is_array($uploaded_file)) { $this->httpError(HTTP_ERR_OPERATION_FAILED, lang('You did not uploaded any file'), true, true); } // if // we are setting base attributes $attachment = new Attachment(); $attachment->setName($uploaded_file['name']); $attachment->setMimeType($uploaded_file['type']); $attachment->setSize($uploaded_file['size']); $attachment->setAttachmentType(ATTACHMENT_TYPE_ATTACHMENT); $attachment->setCreatedBy($this->logged_user); $attachment->setCreatedOn(new DateTimeValue()); // check if uploaded file is image if (!$attachment->isImage()) { $this->httpError(HTTP_ERR_OPERATION_FAILED, lang('Uploaded file is not image'), true, true); } // if $destination_file = get_available_uploads_filename(); if (!move_uploaded_file($uploaded_file['tmp_name'], $destination_file)) { $this->httpError(HTTP_ERR_OPERATION_FAILED, lang('Could not copy uploaded image to work folder'), true, true); } // if if (FIX_UPLOAD_PERMISSION !== false) { @chmod($destination_file, FIX_UPLOAD_PERMISSION); } // if $attachment->setLocation(basename($destination_file)); $save = $attachment->save(); if (!$save || is_error($save)) { @unlink($destination_file); $this->httpError(HTTP_ERR_OPERATION_FAILED, $save->getMessage(), true, true); } // if echo "<img attachment_id='" . $attachment->getId() . "' src='" . $attachment->getViewUrl($this->active_project->getId()) . "' />"; die; break; default: break; } // switch } // if }
private function saveAttachment($file, $mailbox_id) { $attachment = new Attachment(); $attachment->mailbox_id = $mailbox_id; $attachment->attachment_id = $file['file_id']; $attachment->original_path = $file['addresses']['from']['email'] . '/' . $file['message_id'] . '/' . $file['file_name']; $attachment->bytes = $file['size']; $attachment->mime_type = $file['type']; $attachment->file_sha = null; // Compute when downloaded $attachment->etag = null; // Compute when downloaded $attachment->service_created_at = date('r', $file['date_received']); $attachment->service_updated_at = date('r', $file['date_indexed']); $attachment->client_created_at = date('r', $file['date']); $attachment->client_updated_at = null; // never known if (!$attachment->save()) { return false; } Queue::push('ContextIOFileHandlerController@create', ['action' => 'create', 'attachment' => $attachment->toArray()], $this->file_queue_id); return true; }
/** * undocumented function * * @return void * @author paranoid **/ public function actionUpload() { $category_id = $_GET['category_id']; $user_id = $_GET['user_id']; if (strlen(trim($category_id)) == 0) { //$category_id = 30; $category_id = Category::model()->autoCreate(); } ini_set("html_errors", "0"); $upload_name = "Filedata"; $path_info = pathinfo($_FILES[$upload_name]['name']); $file_extension = $path_info["extension"]; $valid_chars_regex = '.A-Z0-9_ !@#$%^&()+={}\\[\\]\',~`-'; // Characters allowed in the file name (in a Regular Expression format) //$screen_name = preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name'])); $screen_name = basename($_FILES[$upload_name]['name']); $time = time(); $file_name = $time . '.' . $file_extension; $put_file_path = API::upload_prefix_dir(); $put_file_to_dir = ATMS_SAVE_DIR . $put_file_path; if (!@move_uploaded_file($_FILES[$upload_name]["tmp_name"], $put_file_to_dir . $file_name)) { echo 'f**k'; exit(0); } $model = new Attachment(); $is_image = false; $w = 0; $h = 0; if (in_array(strtolower($file_extension), API::$IMAGE_EXTENSION)) { $image = Yii::app()->image->load($put_file_to_dir . $file_name); $w = $image->width; $h = $image->height; $is_image = true; } $ati = array('screen_name' => $screen_name, 'path' => $put_file_path . $time, 'w' => $w, 'h' => $h, 'c_time' => Time::now(), 'extension' => $file_extension, 'category_id' => $category_id, 'user_id' => $user_id); $model->attributes = $ati; if ($model->save()) { if ($is_image) { $model->tips = str_pad($w, 4, "_", STR_PAD_LEFT) . '*' . str_pad($h, 4, "_", STR_PAD_RIGHT) . ','; foreach (API::$ATT_IMG_AUTO_SIZE as $k => $v) { $file_path = $put_file_to_dir . $time . '_' . $v . '.' . $file_extension; list($dw, $dh) = explode('_', $v); if ($w > $dw && $h > $dh) { if ($h / $w > $dh / $dw) { if ($k == 'thumb') { $image->resize($dw * 1.2, $dh * 1.2, Image::WIDTH)->crop($dw, $dh, '20', 'center'); } else { $image->resize($dw, $dh, Image::WIDTH); } } else { if ($k == 'thumb') { $image->resize($dw * 1.2, $dh * 1.2, Image::HEIGHT)->crop($dw, $dh, '20', 'center'); } else { $image->resize($dw, $dh, Image::HEIGHT); } } $model->tips .= str_pad($dw, 4, "_", STR_PAD_LEFT) . '*' . str_pad($dh, 4, "_", STR_PAD_RIGHT) . ','; } $image->save($file_path); } $model->save(); rename($put_file_to_dir . $file_name, $put_file_to_dir . $time . '_' . $w . '_' . $h . '.' . $file_extension); /* $file_path_l = $put_file_to_dir.$time.'_800_600'.'.'.$file_extension; $file_path_t = $put_file_to_dir.$time.'_160_120'.'.'.$file_extension; $file_path_g = $put_file_to_dir.$time.'_48_48'.'.'.$file_extension; if( $w >800 && $h>600){ $image->resize(800, 600); } $image->save($file_path_l); if( $w >160 && $h>120){ $image->resize(160, 120); } //,Image::NONE); $image->save($file_path_t); $image->resize(48, 48); $image->save($file_path_g); $model->tips = str_pad($w, 4, "_", STR_PAD_LEFT).'*'. str_pad($h,4,"_", STR_PAD_RIGHT).','; $model->tips .= '_800*600_,'; $model->tips .= '_160*120_,'; $model->tips .= '__48*48__,'; $model->save(); rename($put_file_to_dir.$file_name, $put_file_to_dir.$time.'_'.$w.'_'.$h.'.'.$file_extension ); */ } } }
public function returnUrl() { /* * * 功能:支付宝页面跳转同步通知页面 * 版本:3.3 * 日期:2012-07-23 * 说明: * 以下代码只是为了方便商户测试而提供的样例代码,商户可以根据自己网站的需要,按照技术文档编写,并非一定要使用该代码。 * 该代码仅供学习和研究支付宝接口使用,只是提供一个参考。 *************************页面功能说明************************* * 该页面可在本机电脑测试 * 可放入HTML等美化页面的代码、商户业务逻辑程序代码 * 该页面可以使用PHP开发工具调试,也可以使用写文本函数logResult,该函数已被默认关闭,见alipay_notify_class.php中的函数verifyReturn */ // require_once("alipay.config.php"); // require_once("lib/alipay_notify.class.php"); require_once public_path() . "/alipay/alipay.config.php"; require_once public_path() . "/alipay/lib/alipay_notify.class.php"; //计算得出通知验证结果 $alipayNotify = new AlipayNotify($alipay_config); $verify_result = $alipayNotify->verifyReturn(); if ($verify_result) { //验证成功 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //请在这里加上商户的业务逻辑程序代码 //——请根据您的业务逻辑来编写程序(以下代码仅作参考)—— //获取支付宝的通知返回参数,可参考技术文档中页面跳转同步通知参数列表 //商户订单号 $out_trade_no = $_GET['out_trade_no']; //支付宝交易号 $trade_no = $_GET['trade_no']; //交易状态 $trade_status = $_GET['trade_status']; if ($_GET['trade_status'] == 'TRADE_FINISHED' || $_GET['trade_status'] == 'TRADE_SUCCESS') { //判断该笔订单是否在商户网站中已经做过处理 //如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序 //如果有做过处理,不执行商户的业务程序 // POST TASK $academy_id = Cookie::get('school_id_session'); $sTask = Session::get('task'); if ($academy_id == NULL) { return Redirect::to('/task/create/step-3')->with('message', 'no-school'); } $task = new Task(); $task->trade_no = $out_trade_no; $task->user_id = Auth::user()->id; // $task->type = Session::get('type'); // $task->title = Session::get('title'); // $task->detail = Session::get('detail'); // $task->category_id = Session::get('category_id'); $task->type = $sTask['type']; $task->title = $sTask['title']; $task->detail = $sTask['detail']; $task->category_id = $sTask['category_id']; if ($sTask['type'] == 1) { // $task->amount = Session::get('amount'); $task->amount = $sTask['amount']; } else { if ($sTask['type'] == 2) { // $task->amountStart = Session::get('amountStart'); // $task->amountEnd = Session::get('amountEnd'); $task->amountStart = $sTask['amountStart']; $task->amountEnd = $sTask['amountEnd']; } } // $task->amount = Session::get('amount'); // $task->expiration = Session::get('expiration'); $task->expiration = $sTask['expiration']; $task->state = 1; $task->place = $academy_id; $task->save(); $credit = Auth::user()->credit; // dd($task->category_id); User::where('id', Auth::user()->id)->update(['credit' => $credit - 50]); if ($sTask['hire'] != NULL) { // $hired_user = User::where('id', Session::get('hire'))->first(); $hired_user = User::where('id', $sTask['hire'])->first(); $message = new Message(); $message->from_user_id = Auth::user()->id; $message->to_user_id = $hired_user->id; $message->message = "Can you help me do this task " . "<a class='message-task-title' target='blank' href=\"/task/{$task->id}\">{$task->title}</a> ?"; $message->save(); } // if (Session::has('file_name') && Session::get('file_name') != "") { if ($sTask['file_name'] != "") { // dd(Session::get('file_name')); $attachment = new Attachment(); // $attachment->file_name = Session::get('file_name'); $attachment->file_name = $sTask['file_name']; $attachment->task_id = $task->id; $attachment->save(); $attachment->file_hash = md5($attachment->id . $attachment->created_at . $attachment->file_name . $attachment->task_id); $attachment->file_ext = Util::getExtension($attachment->file_name); $attachment->save(); // Session::set('file_hash', $attachment->file_hash); if (!file_exists(public_path() . '/file/' . Auth::user()->id . '/')) { mkdir(public_path() . '/file/' . Auth::user()->id . '/'); } if ($attachment->file_ext == "") { copy(public_path() . '/upload/cache/' . $attachment->file_name, public_path() . '/file/' . Auth::user()->id . '/' . $attachment->file_hash); } else { copy(public_path() . '/upload/cache/' . $attachment->file_name, public_path() . '/file/' . Auth::user()->id . '/' . $attachment->file_hash . '.' . $attachment->file_ext); } } return Redirect::to('order/' . $out_trade_no . '/success'); } else { echo "trade_status=" . $_GET['trade_status']; } // echo "验证成功<br />"; //——请根据您的业务逻辑来编写程序(以上代码仅作参考)—— ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// } else { //验证失败 //如要调试,请看alipay_notify.php页面的verifyReturn函数 echo "验证失败"; } // return View::make('pay.return_url'); }
/** * Update the specified resource in storage. * * @param Request $request * @param int $id * @return Response */ public function update(article $article, Request $request) { $article->user_id = Auth::user()->id; $article->title = $request->title; $article->body = $request->body; $article->attach = $request->image; $article->edit_version = $article->edit_version + 1; if ($article->save()) { $files = $request->file('attach'); foreach ($files as $index => $file) { if ($file->isValid()) { if ($file->move($this->upload_dir . $article->id . '/', $article->edit_version . $file->getClientOriginalName())) { $attachment = new Attachment(); $attachment->article_id = $article->id; $attachment->name = $article->edit_version . $file->getClientOriginalName(); $attachment->description = "Dis"; $attachment->save(); if ($index === 0) { $article->attach = $attachment->name; $article->save(); } } } } $request->session()->flash('edited', 'Task was successful!'); } return redirect('articles/' . $article->id . '/edit/'); }
/** * Creates attachment from uploaded file * * @param array $file * @param ApplicationObject $parent * @return Attachment */ function &make_attachment($file, $parent = null) { if (!isset($file) || !isset($file['tmp_name'])) { return new Error(lang('File is not uploaded')); } // if $destination_file = get_available_uploads_filename(); if (!move_uploaded_file($file['tmp_name'], $destination_file)) { return new Error(lang('Could not move uploaded file to uploads directory')); } // if $attachment = new Attachment(); $attachment->setName($file['name']); $attachment->setLocation(basename($destination_file)); $attachment->setMimeType(array_var($file, 'type', 'application/octet-stream')); $attachment->setSize(array_var($file, 'size', 0)); if (instance_of($parent, 'ApplicationObject')) { $attachment->setParent($parent); } // if $save = $attachment->save(); if (!$save || is_error($save)) { @unlink($destination_file); return $save; } // if return $attachment; }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Attachment(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Attachment'])) { $model->attributes = $_POST['Attachment']; if ($model->save()) { $this->redirect(array('view', 'id' => $model->id)); } } $leafs = Category::model()->ileafs(array('ident' => 'attachment', 'include' => true)); $this->render('create', array('model' => $model, 'leafs' => $leafs)); }