本文整理汇总了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;
}