<!doctype html public "-//w3c//dtd html 4.01 transitional//en">
<html>
<head>
<title> پروژه لوگین و آپلود فایل</title>
<?php
//load the config file
include("config.php");
//if the for has submittedd
if (isset($_POST['upForm'])){
$file_type = $_FILES['imgfile']['type'];
$file_name = $_FILES['imgfile']['name'];
$file_size = $_FILES['imgfile']['size'];
$file_tmp = $_FILES['imgfile']['tmp_name'];
//check if you have selected a file.
if(!is_uploaded_file($file_tmp)){
echo "خطا : لطفا یک عکس برای آپلود انتخاب کنید <br>--<a href=\"$_SERVER[PHP_SELF]\">برگشت</a>";
exit(); //exit the script and don't do anything else.
}
//check file extension
$ext = strrchr($file_name,'.');
$ext = strtolower($ext);
if (($extlimit == "yes") && (!in_array($ext,$limitedext))) {
echo "مشکل در آپلود فایل <br>--<a href=\"$_SERVER[PHP_SELF]\">برگشت</a>";
exit();
}
//get the file extension.
$getExt = explode ('.', $file_name);
$file_ext = $getExt[count($getExt)-1];
//create a random file name
$rand_name = md5(time());
$rand_name= rand(0,999999999);
//get the new width variable.
$ThumbWidth = $img_thumb_width;
//keep image type
if($file_size){
if($file_type == "image/pjpeg" || $file_type == "image/jpeg"){
$new_img = imagecreatefromjpeg($file_tmp);
}elseif($file_type == "image/x-png" || $file_type == "image/png"){
$new_img = imagecreatefrompng($file_tmp);
}elseif($file_type == "image/gif"){
$new_img = imagecreatefromgif($file_tmp);
}
//list width and height and keep height ratio.
list($width, $height) = getimagesize($file_tmp);
$imgratio=$width/$height;
if ($imgratio>1){
$newwidth = $ThumbWidth;
$newheight = $ThumbWidth/$imgratio;
}else{
$newheight = $ThumbWidth;
$newwidth = $ThumbWidth*$imgratio;
}
//function for resize image.
if (function_exists(imagecreatetruecolor)){
$resized_img = imagecreatetruecolor($newwidth,$newheight);
}else{
die("خطا : بروی سرور شما نرم افزار کوچک کردن عکس نصب نمی باشد");
}
imagecopyresized($resized_img, $new_img, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
//save image
ImageJpeg ($resized_img,"$path_thumbs/$rand_name.$file_ext");
ImageDestroy ($resized_img);
ImageDestroy ($new_img);
//print message
echo "<br>سایز کوچک عکس : <a href=\"$path_thumbs/$rand_name.$file_ext\">$path_thumbs/$rand_name.$file_ext</a>";
}
//upload the big image
move_uploaded_file ($file_tmp, "$path_big/$rand_name.$file_ext");
echo "<br>سایز بزرگ عکس : <a href=\"$path_big/$rand_name.$file_ext\">$path_big/$rand_name.$file_ext</a>";
echo "<br><br>--<a href=\"$_SERVER[PHP_SELF]\">بازگشت</a>";
}else{ //if the form hasn't been submitted.
//print the form
echo "<script>
function view_img(img_name){
document[img_name].src = upForm.imgfile.value;
document[img_name].width = 150;
}
</script>\n\n
<br><h3>انتخاب برای آپلود عکس از روی کامپیوتر شما</h3>\n
<form method=\"post\" name=\"upForm\" enctype=\"multipart/form-data\" action=\"$_SERVER[PHP_SELF]\">\n
<input type=\"file\" name=\"imgfile\" onchange=\"javascript:view_img('img_vv');\"> <img src='' name='img_vv' width='0'><br>\n
آپلود و تغییر سایز تا <b>$img_thumb_width</b> عکس بصورت همزمان .
<br><input type=\"Submit\" name=\"upForm\" value=\"آپلود و تغییر سایز\">\n
</form>
<a href=\"view_gallery.php\">نمایش گالری</a>";
}
?>