本文整理汇总了PHP中Upload::find方法的典型用法代码示例。如果您正苦于以下问题:PHP Upload::find方法的具体用法?PHP Upload::find怎么用?PHP Upload::find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Upload
的用法示例。
在下文中一共展示了Upload::find方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: delete
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);
}
示例2: actionUploadAjax
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();
}
示例3: edit
/**
* 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'));
}
示例4: User
/**
* 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";
}
示例5: register
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);
}
}
示例6: create
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);
}
}
示例7: returnExtFormElements
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)) {
//.........这里部分代码省略.........
示例8: Upload
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));
}
示例9: post_update_images_order
/**
* 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;
}
示例10: downloadfile
public function downloadfile($id)
{
$upload = Upload::find($id);
return Response::download(public_path() . $upload->file_url, $upload->file_name);
}