PDA

View Full Version : سوال: چجوری ارایه تعرف کنم تا 3 بار عکسا خونده بشن اپلود بشن و مسیرشون تو دیتابیس ذخیره بشه!



saeed-71
دوشنبه 06 آبان 1392, 09:26 صبح
سلام.
چجوری ارایه تعرف کنم تا 3 بار عکسا خونده بشن اپلود بشن و مسیرشون تو دیتابیس ذخیره بشه!
همچنین سایز عکسمم به عرض 800 و طول 600 در بیاد
اینم کد:


if(!defined('ROOT')) { define('ROOT', str_replace('\\', '/', dirname(__FILE__))); }
$photo = &$_FILES['img'];
$allowedtypes = array('image/gif', 'image/jpeg', 'image/png', 'image/bmp');
if($photo['error'] == 0 && $photo['size'] <= 2097152 && in_array($photo['type'], $allowedtypes)) {
do {
$photoName1 =time();
sleep(1);
} while(file_exists(ROOT . '/upload/' . $photoName1 . '.jpg'));
switch(strtolower($photo['type'])) {
case 'image/bmp':
$src = ImageCreateFromWBMP($photo['tmp_name']);
break;
case 'image/gif':
$src = ImageCreateFromGIF($photo['tmp_name']);
break;
case 'image/jpeg':
$src = ImageCreateFromJPEG($photo['tmp_name']);
break;
case 'image/png':
$src = ImageCreateFromPNG($photo['tmp_name']);
break;
}
$width = ImageSX($src);
$height = ImageSY($src);
$dst = ImageCreateTrueColor($width, $height);
ImageFill($dst, 0, 0, ImageColorAllocate($dst, 255, 255, 255));
ImageCopy($dst, $src, 0, 0, 0, 0, $width, $height);
ImageJPEG($dst, ROOT . '/upload/' . $photoName1 . '.jpg', 100);
ImageDestroy($dst);
ImageDestroy($src);
}