示例#1
0
move_uploaded_file($_FILES["file"]["tmp_name"], "../upload/" . $fname);
$img = new imagick();
$img->setResolution(600, 600);
$img->readimage("../upload/" . $fname);
$pdfLength = $img->getNumberImages();
$sql = "INSERT INTO `magazine` (`size`, `series`, `issue`, `createtime`, `isnew`, `status`) VALUES (" . $pdfLength . "," . $series . ",0, '" . date("Y-m-d h:i:s") . "', 1, 0)";
mysql_query($sql, $conn);
$id = mysql_insert_id($conn);
if (!file_exists("../../magazine/")) {
    mkdir("../../magazine/");
}
mkdir("../../magazine/" . $id);
mkdir("../../magazine/" . $id . "/small");
$img->setImageFormat('jpeg');
for ($i = 0; $i < $pdfLength; $i++) {
    $img->setIteratorIndex($i);
    $img->scaleImage(1000, 0);
    $fname = md5($file_name[1] . date() . rand(0, 100000)) . ".jpg";
    while (file_exists("../../magazine/" . $id . "/" . $fname)) {
        $fname = md5($file_name[1] . date() . rand(0, 100000)) . ".jpg";
    }
    $sql = "INSERT INTO `pages` (`magazine`, `name`, `position`) VALUES (" . $id . ", '" . $fname . "'," . $i . ")";
    mysql_query($sql, $conn);
    $img->writeImage("../../magazine/" . $id . "/" . $fname);
    $img->scaleImage(200, 0);
    $img->writeImage("../../magazine/" . $id . "/small/" . $fname);
}
$img->clear();
$img->destroy();
recursiveRemoveDirectory("../upload/");
function recursiveRemoveDirectory($directory)