本文整理汇总了PHP中UUID::uuidv4方法的典型用法代码示例。如果您正苦于以下问题:PHP UUID::uuidv4方法的具体用法?PHP UUID::uuidv4怎么用?PHP UUID::uuidv4使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UUID
的用法示例。
在下文中一共展示了UUID::uuidv4方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: saveImg
public function saveImg($images, $adid)
{
$dbc = $this->database();
$uuidGen = new UUID();
$log = new Log("Image", "save", "logs");
$target_dir = "uploads/";
if (is_dir($target_dir) === false) {
mkdir($target_dir);
}
foreach ($images["name"] as $key => $value) {
$uuid = $uuidGen->uuidv4();
$imageFileType = pathinfo(basename($images["name"][$key]), PATHINFO_EXTENSION);
$target_file = $target_dir . $uuid . "." . $imageFileType;
$check = getimagesize($images["tmp_name"][$key]);
if ($check !== false) {
$log->info("File is an image.");
$uploadOk = 1;
} else {
$log->error("File is not an image.");
$uploadOk = 0;
}
if ($images["size"][$key] > 1000000) {
$log->error("Sorry, your file is too large.");
$uploadOk = 0;
}
if ($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" && $imageFileType != "gif") {
$log->error("Sorry, only JPG, JPEG, PNG & GIF files are allowed.");
$uploadOk = 0;
}
if ($uploadOk == 1) {
move_uploaded_file($images["tmp_name"][$key], $target_file);
$query = "INSERT into images (adid, imgpath) VALUES (:adid, :imgpath)";
$stmt = $dbc->prepare($query);
$stmt->bindValue(":adid", $adid, PDO::PARAM_STR);
$stmt->bindValue(":imgpath", $target_file, PDO::PARAM_STR);
$stmt->execute();
$log->info("{$target_file} was uploaded successfully.");
} else {
$log->error("file was not uploaded.");
}
}
$log->info("{$paths}");
unset($uuidGen);
unset($log);
}