当前位置: 首页>>代码示例>>PHP>>正文


PHP Sample::firstOrNew方法代码示例

本文整理汇总了PHP中Sample::firstOrNew方法的典型用法代码示例。如果您正苦于以下问题:PHP Sample::firstOrNew方法的具体用法?PHP Sample::firstOrNew怎么用?PHP Sample::firstOrNew使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Sample的用法示例。


在下文中一共展示了Sample::firstOrNew方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: upload

 public function upload()
 {
     if (!file_exists($_ENV['MALWARE_STORAGE_PATH'])) {
         mkdir($_ENV['MALWARE_STORAGE_PATH'], 0777, true);
     }
     $input = Input::all();
     $files = Input::file();
     foreach ($files as $file) {
         try {
             $filename = md5_file($file);
             $sample = Sample::firstOrNew(array('md5' => $filename));
             $sample->filename = $file->getClientOriginalName();
             $sample->filesize = $file->getSize();
             $file->move($_ENV['MALWARE_STORAGE_PATH'], $filename);
             if (isset($input['VTscan'])) {
                 $this->scanFileOnVirusTotal($sample, TRUE);
             } else {
                 $this->scanFileOnVirusTotal($sample, FALSE);
             }
             $sample->save();
             // tags processing
             $tag_name_str = 'tag_' . preg_replace('/[. ]/', "_", $sample->filename);
             if (isset($input[$tag_name_str])) {
                 $tags = trim($input[$tag_name_str]);
                 if ($tags != "") {
                     $tags = explode(";", $tags);
                     $tagIds = array();
                     // Tags
                     foreach ($tags as $tag) {
                         $tag = Tag::firstOrCreate(array('tag' => $tag));
                         $tagIds[] = $tag->id;
                     }
                     // Sample <=> Tags
                     $sample->tags()->sync($tagIds);
                 }
             }
             // writeups processing
             $writeup_name_str = 'writeup_' . preg_replace('/[. ]/', "_", $sample->filename);
             if (isset($input[$writeup_name_str])) {
                 $writeups = $input[$writeup_name_str];
                 foreach ($writeups as $url) {
                     if ($url == "") {
                         continue;
                     }
                     $writeup = new Writeup();
                     $writeup->url = $url;
                     $writeup->title = $this->getUrlTitle($url);
                     $writeup->sample()->associate($sample);
                     $writeup->save();
                 }
             }
             $samples[] = $sample;
         } catch (Exception $e) {
             Log::info($e);
             Response::json("Error occured :( Try to upload again");
         }
     }
     return $sample;
 }
开发者ID:wxdublin,项目名称:malwaRE,代码行数:59,代码来源:HomeController.php


注:本文中的Sample::firstOrNew方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。