Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)
Paste
Pasted as PHP by int20 ( 18 years ago )
<?php
session_start();
if(!include($_SERVER['DOCUMENT_ROOT'] . "/req/config.inc.php"))
{
echo "Abnormal program termination: can't see configuration files. Stopped.";
exit();
}
include($_SERVER['DOCUMENT_ROOT'] . "/req/thumbnail2.php");
echo $photosPath . "<br>";
echo $thumbsPath . "<br>";
echo $originalPhotoPath . "<br>";
// 1. Генерируем новое Ð¸Ð¼Ñ Ñ„Ð°Ð¹Ð»Ð°.
echo "Сгенерированное Ð¸Ð¼Ñ Ñ„Ð°Ð¹Ð»Ð°: ";
echo strtolower($photo_filename = $_POST['id'] . "-" . mt_rand(100000,999999).getFileType($_FILES['userfile']['name']));
// 2. Кладём оригинал в originals.
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $originalPhotoPath . "/" . $photo_filename))
{
echo "<br>Original: <a href='http://dev.estspb.ru/photos/originals/" . $photo_filename . "'>here</a><br>";
} else {
print "Possible file upload attack! Here's some debugging info:n";
print "Possible file upload attack! Ð”Ð¾Ð¿Ð¾Ð»Ð½Ð¸Ñ‚ÐµÐ»ÑŒÐ½Ð°Ñ Ð¾Ñ‚Ð»Ð°Ð´Ð¾Ñ‡Ð½Ð°Ñ Ð¸Ð½Ñ„Ð¾Ñ€Ð¼Ð°Ñ†Ð¸Ñ:n";
print_r($_FILES);
}
// 3. Пишем thumbnail 150x150 в thumbs
$options = array(
'width' => 150,
'height' => 150,
'type' => IMAGETYPE_JPEG,
);
Thumbnail::output($originalPhotoPath."/".$photo_filename, $thumbsPath."/".$photo_filename, $options);
echo "<br>Thumnail: <a href='http://dev.estspb.ru/photos/thumbs/".$photo_filename."'>here</a>";
// 4. Пишем 450х450
$options = array(
'width' => 450,
'height' => 450,
'type' => IMAGETYPE_JPEG,
'method' => THUMBNAIL_METHOD_SCALE_MIN,
);
Thumbnail::output($originalPhotoPath."/".$photo_filename, $photosPath."/".$photo_filename, $options);
echo "<br>Photo: <a href='http://dev.estspb.ru/photos/".$photo_filename."'>here</a>";
$DB->query("INSERT INTO photos (filename, pid) VALUES (?, ?)", $photo_filename, $_POST['id']);
header("Location: /cars/car_photo.php?id=".$_POST['id']);
exit();
function getFileType($yourfile){
$filedes = array(
".gif",
".jpg",
".png",
".JPG",
".JPEG",
".GIF",
".PNG"
);
$fileext = array(".gif",".jpg",".png", ".JPG", ".JPEG", ".GIF", ".PNG");
$ext = strrchr($yourfile,'.');
if (in_array($ext,$fileext)) {
$ext2 = array_search($ext, $fileext);
$filetype = $filedes[$ext2];
} else {
$filetype = "Wrong File Format! Please, use JPG Files. :)";
}
return $filetype;
}
?>
Revise this Paste