本文整理汇总了PHP中app\models\File类的典型用法代码示例。如果您正苦于以下问题:PHP File类的具体用法?PHP File怎么用?PHP File使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了File类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
}
示例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']);
}
示例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);
}
示例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');
}
示例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/');
}
示例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');
}
示例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');
}
示例8: actionEdit
public function actionEdit($id = null)
{
if (null === $id || 'new' === $id) {
$this->data->item = new File();
} else {
$this->data->item = File::findByPK($id);
}
}
示例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.');
}
}
示例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));
}
}
示例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());
}
}
示例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();
}
示例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');
}
示例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);
}
示例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;
}
}