public function delete($id) { $upload = Upload::find($id); $upload->delete(); $success = new stdClass(); $success->{$upload->filename} = true; return Response::json(array('files' => array($success)), 200); }
public function actionUploadAjax($id) { if (Yii::$app->request->isAjax) { $upload = Upload::find()->where(['post_id' => $id])->asArray()->all(); echo Json::encode($upload); } else { echo Json::encode("0"); } Yii::$app->end(); }
/** * Show the form for editing the specified institution. * * @param int $id * @return Response */ public function edit($id) { $institution = Institution::find($id); $fileids = json_decode($institution->logo); $files = array(); foreach ($fileids as $fileid) { $upload = Upload::find($fileid); if (isset($upload)) { $newurl = URL::asset($upload->publicpath() . $upload->filename); $success = new stdClass(); $success->name = $upload->filename; $success->size = $upload->size; $success->url = $newurl; $success->thumbnailUrl = $newurl; $success->deleteUrl = action('UploadController@delete', $upload->id); $success->deleteType = 'DELETE'; $success->fileID = $upload->id; $files[] = $success; } } $json = json_encode(array('files' => $files)); return View::make('institutions.edit', compact('institution', 'json')); }
/** * Specification: * -------------- * * - URL: /api/hist * * - Request: * + k = apikey * * - Response (history, success): * > 0 * > {id},{YYYY-MM-DD HH:MM:SS},{http://pointer/url},{filename.jpg},{views},{unknown} * * - Response (failure): * > -1 */ $pFunctions->requireRequest("k"); $pUser = new User(); $pUpload = new Upload(); if (!$pUser->loadAPIKey($_REQUEST["k"])) { throw new Exception("Invalid API key."); } /** * We'll just browse our uploaded files, casually display things. */ $aArguments = array("params" => array("users_id = '{$pUser->id}'", "is_deleted = '0'"), "sort" => array("timestamp" => "DESC"), "p" => 0, "rpp" => 10); $aUploads = $pUpload->find($aArguments); echo "0\r\n"; foreach ($aUploads as $pItem) { echo "{$pItem->id}," . date("Y-m-d H:i:s", $pItem->timestamp) . ",{$pItem->web_url},{$pItem->file_name},{$pItem->views},1\r\n"; }
public static function register($vidId, $channelId, $title, $desc, $tags, $thumb, $visibility) { $video = Video::find($vidId); Upload::find(array('conditions' => array('video_id = ?', $vidId)))->delete(); $video->title = $title; $video->description = $desc; $video->tags = $tags; $video->visibility = in_array($visibility, array(0, 1, 2)) ? $visibility : 0; if ($visibility == Config::getValue_("vid_visibility_public")) { $video->published_once = 1; } else { $video->published_once = 0; } $video->tumbnail = Utils::upload($thumb, 'img', $vidId, $channelId, $video->getThumbnail()); $video->save(); if ($visibility == 2) { Video::sendUploadNotification($vidId, $channelId); } }
public function create($request) { $req = $request->getParameters(); if (isset($req['channelId'], $req['uploadId']) && UserChannel::find($req['channelId'])->belongToUser(Session::get()->id) && Upload::exists(array('id' => $req['uploadId'], 'channel_id' => $req['channelId']))) { // if(isset($req['save-description']) && isset($req['save-description-name']) && isset($req['video-description'])){ // $newdesc=array(); // $newdesc['name']=$req['save-description-name']; // $newdesc['description']=$req['video-description']; // $newdesc['users_channels_id']=$req['channelId']; // PredefinedDescription::create($newdesc); // } $upload = Upload::find($req['uploadId']); $videoId = $upload->video_id; if (isset($req['_FILES_']['video'])) { $ext = explode('.', $req['_FILES_']['video']['name']); $ext = $ext[count($ext) - 1]; $videoInfos = Utils::upload($req['_FILES_']['video'], 'vid', $videoId, $req['channelId']); $videoPath = $videoInfos[0]; $duration = $videoInfos[1]; $thumbnailPath = WEBROOT . 'uploads/' . $req['channelId'] . '/' . $videoId . '.' . $ext . '.jpg'; Video::createTemp($videoId, $req['channelId'], $videoPath, $thumbnailPath, $duration); return new Response(200); } else { if (isset($req['video-title'], $req['video-description'], $req['video-tags'], $req['video-visibility'])) { Video::register($videoId, $req['channelId'], $req['video-title'], $req['video-description'], $req['video-tags'], $req['_FILES_']['upload-tumbnail'], $req['video-visibility']); } return new RedirectResponse(WEBROOT . 'watch/' . $videoId); } } else { return new Response(403); } }
public static function returnExtFormElements() { $mod_tpl = static::returnTpl(); $class = __CLASS__; /** * EXTFORM UPLOAD */ ExtForm::add("upload", function ($name = 'upload', $value = '', $params = null) use($mod_tpl, $class) { ## default template $tpl = "extform_upload"; ## custom template if (@$params['tpl']) { $tpl = $params['tpl']; unset($params['tpl']); } #Helper::dd($value); if ($value === false || $value === null) { $val = Form::text($name); preg_match("~value=['\"]([^'\"]+?)['\"]~is", $val, $matches); #Helper::d($matches); $val = (int) @$matches[1]; if ($val > 0) { $value = Upload::firstOrNew(array('id' => $val)); } } elseif (is_numeric($value)) { $value = Upload::find($value); } #Helper::dd($params); ## return view with form element return View::make($mod_tpl . $tpl, compact('name', 'value', 'params')); }, function ($params) use($mod_tpl, $class) { #Helper::d($params); $file = isset($params['file']) ? $params['file'] : false; $upload_id = isset($params['upload_id']) ? $params['upload_id'] : false; $delete = isset($params['delete']) ? $params['delete'] : false; $return = isset($params['return']) ? $params['return'] : 'id'; $module = isset($params['module']) ? $params['module'] : NULL; $unit_id = isset($params['unit_id']) ? $params['unit_id'] : NULL; ## Find file $upload = false; if (is_numeric($upload_id)) { $upload = Upload::find($upload_id); } ## Delete if ($delete && is_object($upload)) { #Helper::dd($upload->fullpath()); @unlink($upload->fullpath()); $upload->delete(); if (!is_object($file)) { return NULL; } } ## If new file uploaded if (is_object($file)) { $mimetype = $file->getMimeType(); $mimes = explode('/', $mimetype); ## Move file $dir = Config::get('site.uploads_dir', public_path('uploads/files')); $file_name = time() . "_" . rand(1000, 1999) . '.' . $file->getClientOriginalExtension(); $file->move($dir, $file_name); $path = preg_replace("~^" . addslashes(public_path()) . "~is", '', $dir . '/' . $file_name); #Helper::dd(filesize($dir . '/' . $file_name)); $input = array('path' => $path, 'original_name' => $file->getClientOriginalName(), 'filesize' => filesize($dir . '/' . $file_name), 'mimetype' => $mimetype, 'mime1' => @$mimes[0], 'mime2' => @$mimes[1], 'module' => $module, 'unit_id' => $unit_id); ## Create new upload object if file not found if (!is_object($upload)) { $upload = new Upload(); $upload->save(); } ## Update upload record with new path $upload->update($input); ## Return return @$upload->{$return}; } ## Return exist upload_id, if no actions if (is_numeric($upload_id)) { return $upload_id; } }); /** * EXTFORM UPLOADS */ ExtForm::add("uploads", function ($name = 'uploads', $values = array(), $params = null) use($mod_tpl, $class) { ## default template $tpl = "extform_uploads"; ## custom template if (@$params['tpl']) { $tpl = $params['tpl']; unset($params['tpl']); } #Helper::dd($values); /* if ( $value === false || $value === null ) { $val = Form::text($name); preg_match("~value=['\"]([^'\"]+?)['\"]~is", $val, $matches); #Helper::d($matches); $val = (int)@$matches[1]; if ( $val > 0 ) { $value = Upload::firstOrNew(array('id' => $val)); } } elseif (is_numeric($value)) { $value = Upload::find($value); } */ #Helper::dd($params); $params['multiple'] = 'multiple'; ## return view with form element return View::make($mod_tpl . $tpl, compact('name', 'values', 'params'))->render(); }, function ($params) use($mod_tpl, $class) { $files = isset($params['files']) ? $params['files'] : false; #$upload_id = isset($params['upload_id']) ? $params['upload_id'] : false; $module = isset($params['module']) ? $params['module'] : NULL; $unit_id = isset($params['unit_id']) ? $params['unit_id'] : NULL; #Helper::dd($files); ## If new file uploaded if (isset($files) && is_array($files) && count($files)) { $c = 0; foreach ($files as $f => $file) { if (!is_object($file)) { continue; } $mimetype = $file->getMimeType(); $mimes = explode('/', $mimetype); ## Move file $dir = Config::get('site.uploads_dir', public_path('uploads/files')); $file_name = time() . "_" . rand(1000000, 1999999) . '.' . $file->getClientOriginalExtension(); $file->move($dir, $file_name); #$path = preg_replace("~^" . addslashes(public_path()) . "~is", '', $dir . '/' . $file_name); $path = $dir . '/' . $file_name; #Helper::dd(filesize($dir . '/' . $file_name)); $input = array('path' => $path, 'original_name' => $file->getClientOriginalName(), 'filesize' => filesize($dir . '/' . $file_name), 'mimetype' => $mimetype, 'mime1' => @$mimes[0], 'mime2' => @$mimes[1], 'module' => $module, 'unit_id' => $unit_id); ## Create new upload object if file not found $upload = new Upload(); $upload->save(); ## Update upload record with new path $upload->update($input); ++$c; } return $c > 0; } return false; }); }
function download_single_file($id) { App::import("Model", "Upload"); $upload_model = new Upload(); if (!$id) { $this->Session->setFlash(__('Invalid id for upload', true)); $this->redirect(array('action' => 'index')); } $upload = $upload_model->find('first', array('conditions' => array('Upload.id' => $id))); if (!$upload) { $this->Session->setFlash(__('Invalid id for upload', true)); $this->redirect(array('action' => 'index')); } $this->viewClass = 'Media'; $filename = $upload['Upload']['filename']; $this->set(array('id' => $upload['Upload']['id'], 'name' => substr($filename, 0, strrpos($filename, '.')), 'extension' => substr(strrchr($filename, '.'), 1), 'path' => APP . 'uploads' . DS . $upload['Upload']['ref_model'] . DS . $upload['Upload']['ref_id'] . DS, 'download' => true)); }
/** * Update the order of the returned image IDs * @return boolean */ public function post_update_images_order() { $decoded = json_decode(Input::get('data')); if ($decoded) { foreach ($decoded as $order => $id) { if ($img = Upload::find($id)) { $img->order = $order; $img->save(); } } } return true; }
public function downloadfile($id) { $upload = Upload::find($id); return Response::download(public_path() . $upload->file_url, $upload->file_name); }