本文整理匯總了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);
}