本文整理汇总了PHP中app\models\File类的典型用法代码示例。如果您正苦于以下问题:PHP File类的具体用法?PHP File怎么用?PHP File使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了File类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: save
public function save()
{
if (isset($this->reading) and $this->reading != '') {
$savemodel = new Calibration();
$savemodel->measure = 'mm';
$savemodel->height = $this->reading;
$savemodel->sensorid = $this->sensorid;
$savemodel->datetime = $this->date;
$savemodel->youremail = $this->youremail;
$savemodel->yourname = $this->yourname;
$result = $savemodel->save();
$this->id = $savemodel->sensorid;
return $result;
} else {
$savemodel = new File();
$savemodel->sensorid = $this->sensorid;
$savemodel->startdate = $this->date;
$savemodel->enddate = $this->date;
$savemodel->status = 'processed';
$this->file = UploadedFile::getInstance($this, 'file');
$savemodel->extension = end(explode(".", $this->file->name));
$result = $savemodel->save();
// save to get the ID
$savemodel->filename = $savemodel->id . "_" . $this->file->name;
$path = Yii::getAlias('@app') . Yii::$app->params['uploadPath'] . $savemodel->filename;
if ($result) {
$this->file->saveAs($path);
}
$result = $savemodel->save();
$this->id = $savemodel->sensorid;
return $result;
}
}
开发者ID:ICHydro,项目名称:anaconda,代码行数:33,代码来源:UploaddataForm.php
示例2: UploadFile
public static function UploadFile($request)
{
$type = FileType::findOrFail($request->input('file_type_id'));
$file = new File();
$filename = uniqid();
$newname = $request->input('newname');
if ($request->hasFile('file')) {
if (isset($newname[0])) {
$file->slug = str_replace(['/', '\\'], '', $newname);
} else {
$file->slug = $filename;
}
$file->filename = $filename;
$file->file_ext = $request->file('file')->getClientOriginalExtension();
$file->path_to_file = 'uploads/files/';
if ($type->image) {
$file->path_to_file = 'uploads/images/';
}
$destinationPath = public_path($file->path_to_file);
$request->file('file')->move($destinationPath, $filename . '.' . $file->file_ext);
$file->path_to_file = '/' . $file->path_to_file;
$file->file_type_id = $type->id;
$file->fullname = $file->filename . '.' . $file->file_ext;
$file->description = $request->input('description');
$file->alt_text = $request->input('alt_text');
$file->uploader = null;
$file->path_to_file = $file->path_to_file . $file->fullname;
$file->save();
return redirect()->action('FilesController@index');
}
return back()->withErrors(['File not found. Please try again']);
}
开发者ID:jardayn,项目名称:portfolio,代码行数:32,代码来源:FileUpload.php
示例3: create
public static function create(array $data = array())
{
$file = new File();
$file->fill($data);
$file->save();
$element = new Element();
$element->fill($data);
$file->content()->save($element);
}
开发者ID:emmanuelsf,项目名称:xdrawerl,代码行数:9,代码来源:File.php
示例4: testGenerateName
public function testGenerateName()
{
$file = new File();
$file->generateName('png');
$pathinfo = pathinfo($file->name);
expect($pathinfo)->hasKey('basename');
expect($pathinfo)->hasKey('filename');
expect($pathinfo)->hasKey('extension');
expect($pathinfo['extension'])->equals('png');
}
开发者ID:rkit,项目名称:bootstrap-yii2,代码行数:10,代码来源:FileTest.php
示例5: actionSave
public function actionSave()
{
$item = new File();
$periodStart = date('Y-m-d', strtotime($this->app->request->post->periodStart));
$periodEnd = date('Y-m-d', strtotime($this->app->request->post->periodEnd));
$this->app->request->post->periodStart = $periodStart;
$this->app->request->post->periodEnd = $periodEnd;
$item->fill($this->app->request->post);
$item->save();
$this->redirect('/sources/default/');
}
开发者ID:Alexandr1987,项目名称:barricade,代码行数:11,代码来源:Sources.php
示例6: saveDriver
/**
* Save plugin file if its a valid file
*
* @param file object
* @return String success/failure message
*/
public static function saveDriver($file)
{
$fileName = $file->getClientOriginalName();
$destination = app_path() . '/kblis/plugins/';
try {
$file->move($destination, $fileName);
} catch (Exception $e) {
Log::error($e);
return trans('messages.unwriteable-destination-folder');
}
$className = "\\KBLIS\\Plugins\\" . head(explode(".", last(explode("/", $fileName))));
// Check if the className is a valid plugin file
if (class_exists($className)) {
$dummyIP = "10.10.10.1";
$instrument = new $className($dummyIP);
if (is_subclass_of($instrument, '\\KBLIS\\Instrumentation\\AbstractInstrumentor')) {
$instrument->getEquipmentInfo()['code'];
return trans('messages.success-importing-driver');
} else {
Log::error("invalid-driver-file: " . $className);
}
}
if (File::exists($destination . $fileName)) {
File::delete($destination . $fileName);
}
return trans('messages.invalid-driver-file');
}
开发者ID:echiteri,项目名称:iBLIS,代码行数:33,代码来源:Instrument.php
示例7: add
public function add()
{
$login = Auth::check('member');
if ($this->request->data) {
$software = Software::create($this->request->data);
if ($software->save()) {
$file = File::create();
foreach ($this->request->data['myfile'] as $key => $value) {
$size = $this->request->data['myfile'][$key]['size'];
if ($size >= 600000001) {
$chunksize = $size / 20;
} else {
if ($size <= 600000000 && $size >= 100000000) {
$chunksize = $size / 10;
} else {
if ($size <= 100000000 && $size >= 10000000) {
$chunksize = 10000000;
} else {
$chunksize = 1000000;
}
}
}
$save = $file->save(array('file' => $value, 'software_id' => (string) $software->_id, 'chunkSize' => 10000000));
if (!$save) {
return compact('save');
}
}
}
}
$software = Software::create();
return compact('login', 'software');
}
开发者ID:beeckmpi,项目名称:permanentielijsten,代码行数:32,代码来源:SoftwareController.php
示例8: actionEdit
public function actionEdit($id = null)
{
if (null === $id || 'new' === $id) {
$this->data->item = new File();
} else {
$this->data->item = File::findByPK($id);
}
}
开发者ID:Alexandr1987,项目名称:barricade,代码行数:8,代码来源:Files.php
示例9: findModel
/**
* Finds the File model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return File the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = File::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
开发者ID:andreyvaslv,项目名称:crb,代码行数:15,代码来源:FileController.php
示例10: setPathAttribute
/**
* Get the Complete Name for the user.
*
* @return string
*/
public function setPathAttribute($path)
{
if (!empty($path)) {
$title = Carbon::now()->second . $path->getClientOriginalName();
$this->attributes['path'] = $title;
\Storage::disk('local')->put($title, \File::get($path));
}
}
开发者ID:alfons83,项目名称:tfg,代码行数:13,代码来源:User.php
示例11: saveFile
protected function saveFile(UploadedFile $file)
{
$upload_dir = public_path('img/avatar');
$file_name = 'images-' . date('dmY-His') . '.' . $file->getClientOriginalExtension();
try {
if ($file->move($upload_dir, $file_name)) {
$file = new File();
$file->setAttribute('name', $file_name);
$file->setAttribute('path', $upload_dir);
$file->save();
return $file->id;
} else {
return null;
}
} catch (\Exception $ex) {
return abort(500, $ex->getMessage());
}
}
开发者ID:juliardi,项目名称:jualjasa,代码行数:18,代码来源:ProfileController.php
示例12: destroy
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
$filecount = \App\Models\File::where('file_type_id', $id)->count();
if ($filecount > 0) {
return back()->withMsg('There are files in the category');
}
FileType::findOrFail($id)->delete();
return back();
}
开发者ID:jardayn,项目名称:portfolio,代码行数:15,代码来源:FileTypesController.php
示例13: delete
public function delete($id = null)
{
$user = Session::read('member');
if ($user == "") {
return $this->redirect('/');
}
$remove = File::remove('all', array('conditions' => array('documents_doc_id' => (string) $id)));
$remove = Documents::remove('all', array('conditions' => array('_id' => (string) $id)));
return $this->redirect('ex::dashboard');
}
开发者ID:nilamdoc,项目名称:OxOPDF,代码行数:10,代码来源:ExController.php
示例14: assignFileToRecord
public function assignFileToRecord($fileId, $recordId, $record_video_type)
{
$file = File::findOne($fileId);
if (!$file) {
throw new HttpException(500, 'No file found');
}
$file->record_id = $recordId;
$file->record_file_type = $record_video_type;
return $file->save(false);
}
开发者ID:vfokov,项目名称:tims2,代码行数:10,代码来源:Media.php
示例15: delete
public function delete(Request $request, $banqueId, $fileId)
{
// verify request inputs
if (is_null($fileId)) {
return response()->json(['error' => 'Bad request'], HttpResponse::HTTP_BAD_REQUEST);
} else {
$item = File::where('id_File', '=', $fileId)->delete();
return is_null($item) ? response()->json(['error' => 'Bad request'], HttpResponse::HTTP_BAD_REQUEST) : $item;
}
}
开发者ID:S4M37,项目名称:Project_GangOfThree,代码行数:10,代码来源:FileController.php
示例16: createFileByPath
/**
* Создает экземпляр класса App\Models\File заданный путём $filePath
* @param $filePath - относительный (от проекта), либо абсолютный путь к файлу
* @return bool|\App\Models\File
*/
public function createFileByPath($filePath)
{
$file = false;
$filePath = File::normalizeFilePath($filePath);
if (\File::exists($filePath)) {
$file = $this->createFileFromUploadedFile(new SymphonyFile($filePath, false));
} else {
$this->setErrors(array('message' => 'File not found'));
}
return $file;
}
开发者ID:AniartUA,项目名称:crm,代码行数:16,代码来源:FilesService.php
示例17: load
public function load($envName)
{
$cnt = 0;
$settingsFileName = ".settings-" . $envName;
$settingsPath = self::$app->environmentPath();
$settingsFullFileName = $settingsPath . '/' . $settingsFileName;
if (\File::exists($settingsFullFileName)) {
$cnt = SettingDotEnv::load($settingsPath, $settingsFileName);
} else {
throw new FileNotFoundException($settingsFullFileName);
}
return $cnt;
}
开发者ID:sroutier,项目名称:laravel-5.1-enterprise-starter-kit,代码行数:13,代码来源:Setting.php
示例18: uploadFile
public function uploadFile(Request $request)
{
$user = Auth::user();
$type = $request->type;
$file = $request->file('file');
$ext = strtolower($file->getClientOriginalExtension());
$size = $file->getSize();
$validator = Validator::make(['file' => $file, 'extension' => $ext, 'size' => $size], ['file' => 'required', 'extension' => 'required|in:csv', 'size' => 'max:100000']);
if ($validator->fails()) {
//dd($validator->errors());
return Ajax::info('file format error');
}
$destinationPath = Config::get('app.file_path') . '/' . date('Ym', time());
$save_path = public_path() . '/' . $destinationPath;
$file_name = md5($file->getClientOriginalName() . time()) . '.' . $ext;
if (!is_dir($save_path)) {
mkdir($save_path, 755, true);
}
if ($file->move($save_path, $file_name)) {
$url = url($destinationPath . '/' . $file_name);
$file = new File();
$file->ext = $ext;
$file->type = $type;
$file->name = $file_name;
$file->path = $destinationPath . '/' . $file_name;
$file->uid = $user->id;
$file->url = $url;
$file->size = $size;
$file->created_at = time();
$fid = $file->save();
if ($fid) {
return AJAX::success($result = array('url' => $url, 'name' => $file_name));
} else {
return AJAX::serverError();
}
} else {
return AJAX::info('upload file error');
}
}
开发者ID:nosun,项目名称:laravel_base,代码行数:39,代码来源:UploadController.php
示例19: upload
public function upload()
{
if ($this->validate()) {
foreach ($this->files as $file) {
$model = new File();
$model->collection_id = $this->collection_id;
$model->name = str_replace('.' . $file->extension, '', $file->name);
$model->type = $file->type;
$model->extension = $file->extension;
$model->size = $file->size;
if ($model->save()) {
if (!is_dir($model->filePath)) {
mkdir($model->filePath, 0777, true);
}
$file->saveAs($model->filePath . '/' . $model->fileName);
}
}
return true;
} else {
return false;
}
}
开发者ID:andreyvaslv,项目名称:crb,代码行数:22,代码来源:FileForm.php
示例20: document
public function document()
{
$user = Session::read('member');
$id = md5($user['email']);
$document = Details::find('first', array('conditions' => array('user_id' => (string) $user['_id'])));
// if(count($document)==0){return $this->redirect('/');}
$uploadOk = 1;
if ($this->request->data) {
$extension = pathinfo($this->request->data['file']['name'], PATHINFO_EXTENSION);
$allowed = array('pdf');
if (!in_array(strtolower($extension), $allowed)) {
$msg = "Sorry, only PDF files are allowed.";
$uploadOk = 0;
}
if ($uploadOk = 1) {
$option = 'doc';
$data = array('details_' . $option . '_id' => (string) $document['_id'], 'docname' => $this->request->data['docname'], 'date' => $this->request->data['date'], 'DateTime' => new \MongoDate(), 'keywords' => $this->request->data['keywords'], 'description' => $this->request->data['description'], $option => $this->request->data['file'], $option . '.verified' => 'No', $option . '.IP' => $_SERVER['REMOTE_ADDR']);
$field = 'details_' . $option . '_id';
$Documents = Documents::create($data);
$saved = $Documents->save();
$fileData = array('file' => $this->request->data['file'], 'documents_' . $option . '_id' => (string) $Documents->_id);
$file = File::create();
if ($file->save($fileData)) {
$msg = "Upload OK";
}
$image_address = File::find('first', array('conditions' => array('documents_doc_id' => (string) $Documents->_id)));
if ($image_address['filename'] != "") {
$imagename_address = $image_address['_id'] . '_' . $image_address['filename'];
$path = LITHIUM_APP_PATH . '/webroot/download/' . $imagename_address;
file_put_contents($path, $image_address->file->getBytes());
}
// print_r($path);
$pages = $this->getPDFPages($path);
// Output: 13
// print_r($pages);exit;
unlink($path);
$docdata = array();
foreach ($pages as $page) {
$params = explode(":", $page);
$left = $params[0];
$right = $params[1];
$docdata = array_merge($docdata, array($left => trim($right)));
}
$data = array("document" => $docdata);
$conditions = array("_id" => (string) $Documents->_id);
Documents::update($data, $conditions);
// Use the function
}
}
return $this->redirect('ex::save');
}
开发者ID:nilamdoc,项目名称:OxOPDF,代码行数:51,代码来源:UploadController.php
注:本文中的app\models\File类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论