<!doctype html public "-//w3c//dtd html 4.01 transitional//en">
<html>
<head>
<meta http-equiv="content-language" content="en-us">
<meta http-equiv="content-type" content="text/html; charset=windows-1256">
<title>:: image uploader::</title>
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<script language="JavaScript" type="text/javascript">
<!-- ;
var newwindow;
var wheight = 0, wwidth = 0;
function popimg(url, title, iwidth, iheight, colour) {
var pwidth, pheight;
if ( !newwindow || newwindow.closed ) {
pwidth=iwidth+30;
pheight=iheight+30;
newwindow=window.open('','htmlname','width=' + pwidth +',height=' +pheight + ',resizable=1,top=50,left=10');
wheight=iheight;
wwidth=iwidth;
}
if (wheight!=iheight || wwidth!=iwidth ) {
pwidth=iwidth+30;
pheight=iheight+60;
newwindow.resizeTo(pwidth, pheight);
wheight=iheight;
wwidth=iwidth;
}
newwindow.document.clear();
newwindow.focus();
newwindow.document.writeln('<html> <head> <title>' + title + '<\/title> <\/head> <body bgcolor= \"' + colour + '\"> <center>');
newwindow.document.writeln('<a title="Hit to close!" href="javascript:window.close();"><img src=' + url + ' border=0></a>');
newwindow.document.writeln('<\/center> <\/body> <\/html>');
newwindow.document.close();
newwindow.focus();
}
// Routines to tidy up popup windows when page is left
// Call with an onUnload="tidy5()" in body tag
function tidy5() {
if (newwindow && !newwindow.closed) { newwindow.close(); }
}
</script>
<body bgcolor="#ECF5FF" text="#3399FF" leftmargin="20" topmargin="10" marginwidth="10" marginheight="10" dir="rtl" style="font-size:8pt;font-family:tahoma;">
<?php
/*=========================================\
Author : Mohammed Ahmed(M@@king) \\
TRANSLATOR : Mohammed Ali Abaei \\
Version : 1.1 \\
Date Created: Oct 11 2004 \\
---------------------------- \\
Last Update: August 21 2005 \\
---------------------------- \\
Country : Palestine \\
City : Gaza \\
E-mail : [email protected] \\
E-mail : [email protected] \\
MSN : [email protected] \\
AOL-IM : maa2pal \\
WWW : http://www.maaking.com \\
WWW : http://www.bestscripts.ir \\
Mobile/SMS : 00972-599-622235 \\
\\
===========================================\
---Description -----------------------------------------------------
The Super Global Variable $_FILES is used in PHP 4.x.x.
$_FILES['filetoupload']['size'] ==> Get the Size of the File in Bytes.
$_FILES['filetoupload']['tmp_name'] ==> Returns the Temporary Name of the File.
$_FILES['filetoupload']['name'] ==> Returns the Actual Name of the File.
$_FILES['filetoupload']['type'] ==> Returns the Type of the File.
So if I uploaded the file 'test.doc', the $_FILES['filetoupload']['name']
would be 'phptut.doc' and $_FILES['filetoupload']['type'] would be 'application/msword'.
---------------------------------------------------------------------*/
//**********************************************************************//
// $_FILES['filetoupload'] is the value of //
// file field from the form. <input type="file" name="filetoupload" size="20"> //
//**********************************************************************//
################################################################################
##---------------------------1 - Setup
################################################################################
// this is the upload dir where files will go.
//Don't remove the /
//Chmod it (777)
$hid = $_GET['hid'];
$file_name =$_FILES['filetoupload']['name'];
$T1= $_POST['T1'];
include ("cdb.php");
$sql="SELECT * FROM hotel WHERE id=$hid";
@$result=mysql_query($sql, $database);
echo($upload_dir);
$upload_dir = "images/hotel/" . $hid ."/"; //change to whatever you want.
//51200 bytes = 50KB
echo($upload_dir);
$size_bytes = 2000000; //File Size in bytes (change this value to fit your need)
$extlimit = "yes"; //Do you want to limit the extensions of files uploaded (yes/no)
$limitedext = array(".gif",".jpg",".png",".jpeg"); //Extensions you want files uploaded limited to. also you can use: //array(".gif",".jpg",".jpeg",".png");
include 'jdf.php';
################################################################################
##---------------------------2 - check for directory and writable
################################################################################
//check if the directory exists or not.
if (!is_dir("$upload_dir")) {
mkdir($upload_dir);
mkdir($upload_dir."/th/");
}
//check if the directory is writable.
if (!is_writeable("$upload_dir")){
die (" <p> </p><p> </p><p> </p><p> </p><form><p> </p><p> </p><p> </p><p align=\"center\">خطا: پوشه <b>($upload_dir)</b> قابل نوشتن نيست .لطفا سطح دسترسي به آن را 777 نماييد.</p><p> </p><p> </p><p> </p>");
}
################################################################################
##---------------------------3-1 - code begins here
################################################################################
if(isset($_POST['uploadform'])){
// if you clicked the (Upload File) button. "If you submitted the form" then upload the file.
//begin of uploadform.
// $filename will hold the value of the file name submetted from the form.
$file_tmp = $_FILES['filetoupload']['tmp_name'];
$file_name = $_FILES['filetoupload']['name'];
//Get the Size of the File
$file_size = $_FILES['filetoupload']['size'];
//check if no file selected.
if (!is_uploaded_file($file_tmp)){
echo "<p> </p><p> </p><p> </p><p> </p><form><p> </p><p> </p><p> </p><p align=\"center\">خطا: لطفا فايلي را براي آپلود انتخاب نماييد. <br>»<a href=\"$_SERVER[PHP_SELF]?hid=$hid\">بازگشت</a></p></p><p> </p><p> </p><p> </p>";
exit(); //exit the script and don't do anything else.
}
//Make sure that file size is correct
if ($file_size > $size_bytes){
echo "<p> </p><p> </p><p> </p><p> </p><form><p> </p><p> </p><p> </p><p align=\"center\">خطا: حجم فايل بيش از حد زياد است.. فايل بايد حد اكثر <b>". $size_bytes / 1024 ."</b> KB باشد. <br>»<a href=\"$_SERVER[PHP_SELF]?hid=$hid\">باز گشت</a></p><p> </p><p> </p><p> </p>";
exit();
}
//check file extension
$ext = strrchr($file_name,'.');
if (($extlimit == "yes") && (!in_array(strtolower($ext),$limitedext))) {
echo("خطا: پسوند فايل نادرست است. ");
exit();
}
// Check if file is Already EXISTS.
if(file_exists($upload_dir.$file_name)){
echo "Oops!<p> </p><p> </p><p> </p><p> </p><form><p> </p><p> </p><p> </p><p align=\"center\">فايلي با نام <b>$file_name</b> وجود دارد. <br>»<a href=\"$_SERVER[PHP_SELF]?hid=$hid\">بازگشت</a><p> </p><p> </p><p> </p>";
exit();
}
//to remove spaces from file name we have to replace it with "_".
$file_name = str_replace(' ', '_', $file_name);
//Move the File to the Directory of your choice
//move_uploaded_file('filename','destination') Moves afile to a new location.
if (move_uploaded_file($file_tmp,$upload_dir.$file_name)) {
//tell the user that the file has been uploaded and make him alink.
echo " <p> </p><p> </p><p> </p><p> </p><form><p> </p><p> </p><p> </p><p align=\"center\">فايل (<a href=\"$upload_dir$file_name\">$file_name</a>) آپلود شد. <br>»<a href=\"$_SERVER[PHP_SELF]?hid=$hid\">بازگشت</a><p> </p><p> </p><p> </p>";
require_once('thumb.php');
$thumb=new thumbnail( $upload_dir . $file_name );
$thumb->size_auto(100);
$thumb->jpeg_quality(75);
$thumb->save($upload_dir ."/th/".$file_name);
$T1=trim($T1) ;
$sql = "INSERT INTO discr(id, filename, text) VALUES('$hid', '$file_name' , '$T1' )" ;
$result = mysql_query($sql, $database);
exit();
}else{
// print error if there was a problem moving file.
echo " <p> </p><p> </p><p> </p><p> </p><form><p> </p><p> </p><p> </p><p align=\"center\">مشكلي در انتقال فايل هست.. <br>»<a href=\"$_SERVER[PHP_SELF]?hid=$hid\">بازگشت</a><p> </p><p> </p><p> </p>";
exit();
}
################################################################################
##---------------------------3-2 - code to display the form
################################################################################
//end of if($uploadform).
// If the form has not been submitted, display it!
}else{
//begin of else
// get the all extensions from the array
for($i=0;$i<count($limitedext);$i++){
if (($i<>count($limitedext)-1))$commas=", ";else $commas="";
list($key,$value)=each($limitedext);
$all_ext .= $value.$commas;
}
//print the form
echo "<p align=\"center\"><font size=\"2\" face=\"Tahoma\"></font><br><center><table><form method=\"POST\" enctype=\"multipart/form-data\" action=\"$PHP_SELF?hid=$hid\" align=\"center\" style=\"font-family:tahoma;font-size:8pt;border: 1px dotted #3399FF;width: 330; height: 160\">"
."<br><p align=\"center\"><b>::آپلود فايل::</b><br> - پسوند هاي قابل آپلود: $all_ext</b><br>"
."- حد اكثر حجم فايل = ". $size_bytes / 1024 ."KB "
."<p align=\"center\"><input type=\"file\" name=\"filetoupload\" size=\"20\" style=\"font-family: Tahoma; font-size: 8pt; background-color: #35ACCD\"><br>"
."توضيحات فايل<BR>"
."<textarea name=\"T1\" style=\"height: 107px; width: 157px\"></textarea>"
."<input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"$size_bytes\" size=\"20\" ><br>"
."<input type=\"submit\" value=\"آپلود\" name=\"uploadform\" style=\"font-family: Tahoma; font-size: 8pt;\">"
."</form>"
."</p></table>";
}//end of else
################################################################################
##---------------------Function to delete files and maine------------------------------##
################################################################################
function main($hid,$database,$file){
// if we want to insert a value inside any function we have to global it first.
$sql = "UPDATE hotel SET mainpic='$file' WHERE id='$hid'";
$result = mysql_query($sql, $database);
//delete the file
echo"<h3><font color=red>فايل ($file) در صفحه اصلي قرار گرفت! <br> لطفا صبر كنيد...</font></h3>";
echo "<meta http-equiv=Refresh content=1;url=uplload.php?hid=$hid>";
}
function del($hid,$database,$file,$upload_dir){
// if we want to insert a value inside any function we have to global it first.
$sql = "DELETE FROM discr WHERE id='$hid' AND filename='$file'";
$result = mysql_query($sql, $database);
//delete the file
@unlink($upload_dir."/$file");
@unlink($upload_dir."th/$file");
echo"<h3><font color=red>فايل ($file) حذف شد! <br> لطفا صبر كنيد...</font></h3>";
echo "<meta http-equiv=Refresh content=1;url=uplload.php?hid=$hid>";
}
//define variable to switch between functions
if ( $_GET['action'] == del ){
$file = $_GET['file'];
$hid = $_GET['hid'];
del($hid,$database,$file,$upload_dir);
}
if ( $_GET['action'] == main ){
$file = $_GET['file'];
$hid = $_GET['hid'];
main($hid,$database,$file,$upload_dir);
}
// Here is the most interesting part.
################################################################################
##---------------------------------Added Option ------------------------------##
################################################################################
################################################################################
##---------------------View uploaded files (photo gallery) -------------------##
################################################################################
echo "<br><hr><center><b>عكس هاي آپلود شده</b></center><br>";
// set number of columns for the Gallery.
$cols = 3;
// set aloop for defining columns.
$i =1;
// creating table inorder to use it for columns.
echo "<table width=100% border ='1' bordercolor='#3399FF' cellpadding='10' cellspacing='6'>
<tr>";
//open the dir where files were uploaded inside.
$opendir =opendir($upload_dir);
// create a loop and define a variable called ($file)
// to hold the value of file name located in the directory .
while ($file = readdir($opendir)) {
//exclude anything that doen't look like files.
if($file != '..' && $file !='.' && $file !=''&& $file !='th'){
//dont't read direcories insde our directory.
if (!is_dir($file)){
$sql="SELECT * FROM hotel WHERE id='$hid' ";
@$result=mysql_query($sql, $database);
while ($row = mysql_fetch_assoc($result)) {
$mainpic=$row["mainpic"];
}
$sql="SELECT * FROM discr WHERE id='$hid' AND filename='$file'";
@$result=mysql_query($sql, $database);
while ($row = mysql_fetch_assoc($result)) {
$discr=$row["text"];
}
// since i am using gallery we have to get the width and hieght of photos.
$imgsize = getimagesize ($upload_dir."".$file);
// lets get the file size in byte/kb/mb.
$file_size = filesize($upload_dir."".$file);
if ($file_size >= 1048576){
$show_filesize = number_format(($file_size / 1048576),2) . " MB";
}elseif ($file_size >= 1024){
$show_filesize = number_format(($file_size / 1024),2) . " KB";
}elseif ($file_size >= 0){
$show_filesize = $file_size . " bytes";
}else{
$show_filesize = "0 bytes";
}
//Gets file modification time
$last_modified = jgmdate ("d F Y ", filemtime($upload_dir."".$file));
$last_time = date("H:i:s");
//for images width.
if ($imgsize[0] > 100){
$base_img = "<img src=\"$upload_dir"."th/$file\" border=\"0\" width=\"100\">";
}else{
$base_img = "<img src=\"$upload_dir"."th/$file\" border=\"0\">";
}
//define a variable to hold everthing that will be printed in table's columns.
if($file!=$mainpic){
$all_stuff = "<p align=center style=\"font-size:8pt;font-family:tahoma;\">نام فايل:<b> $file</b> <hr size=1>
<div style=\"width: 120px; height: 120px; z-index: 1; float: left; border: 1px dotted #C0C0C0\" >
<a href=\"javascript:popimg('$upload_dir$file','$file', $imgsize[0], $imgsize[1],'white')\">
$base_img</a>
</div>
<p align=right style=\"font-size:8pt;font-family:tahoma;\">
حجم: $show_filesize<br>
اختيارات:<br> [<a title=\"Delete File\" href=\"javascript:;\" onClick=\"cf=confirm('آيا ميخواهيد اين عکس را حذف نماييد؟');if (cf)window.location='uplload.php?action=del&file=$file&hid=$hid'; return false;\">حذف</a>]<br>
امکانات بيشتر:<br> [<a title=\"main\" href=\"javascript:;\" onClick=\"cf=confirm('آيا از اين عمل مطمئن هستيد');if (cf)window.location='uplload.php?action=main&file=$file&hid=$hid'; return false;\">تعريف به عنوان عکس اصلي</a>]
<br>عرض : $imgsize[0] px
<br>طول : $imgsize[1] px
<br>زمان ايجاد:$last_modified
<br>توضيحات :$discr";
} else {
$all_stuff = "<p align=center style=\"font-size:8pt;font-family:tahoma;\">نام فايل:<b> $file</b> <hr size=1>
<div style=\"width: 120px; height: 120px; z-index: 1; float: left; border: 3px dotted #fffff\" >
<a href=\"javascript:popimg('$upload_dir$file','$file', $imgsize[0], $imgsize[1],'white')\">
$base_img</a>
</div>
<p align=right style=\"font-size:8pt;font-family:tahoma;\">
حجم: $show_filesize<br>
اين فايل در صفحه اصلي قرار ميگيرد
<br>عرض : $imgsize[0] px
<br>طول : $imgsize[1] px
<br>زمان ايجاد:$last_modified
<br>توضيحات :$discr";
}
//divide the loop ($i) and ($cols) if the result is integer
//then print column number 1.
if (is_int($i / $cols)){
echo "<td align='center' valign='top' bgcolor='#F2F2F2'>$all_stuff</td></tr><tr>";
}else{
//else then print column number 2 etc for the next loop.
echo "<td align='center' valign='top' bgcolor='#F2F2F2'>$all_stuff</td>";
}
//add only 1 for the loop ($i).
$i++;
}
}
}//end while loop
closedir($opendir);
clearstatcache();
// print the rest of table.
echo "</tr>
</table>";
//print copyright ;)
echo"<p align=\"center\"><br>Script by: <a href=\"hotel.php\">برگشت به هتلها</a> & <a href=\"index.php\">مديريت</a></p>
</body>
</html>";
?>