<?php
# Variables
$password = "password";
$include_thumb = 1;
$archiveArr = array("folder1/",
"this/is/multi/folder/test/",
"blah",
"more folders/",
"../test me/");
if ( $_POST["submit"] ) {
# Checks to see if the password is correct
if ( $_POST["pass"] <> $password ) {
$note = 'Incorrect password.';
}
# Checks to see if the folder specified actually exists
if ( !is_dir($_POST["sltArchive"]) ) {
$note = 'The folder specified does not exist.';
}
# Checks to make sure that the last character in the folder name is a /
if ( substr($_POST["sltArchive"],strlen($_POST["sltArchive"]),-1) <> "/" ) {
$_POST["sltArchive"] = $_POST["sltArchive"] . "/";
}
# Checks to make sure the folder is writeable
if ( !is_writeable($_POST["sltArchive"]) ) {
$note = 'The folder cannot be written too';
}
# Sets directory and image names for upload
$img_tmp_name = $_POST["sltArchive"] . date("m.d.y h.i.s") . " - " . $_FILES["img1"]["name"];
$img_tmp_name_th = $_POST["sltArchive"] . date("m.d.y h.i.s") . " - th_" . $_FILES["img1"]["name"];
# Checks to see if the image is already on the server
if ( $_FILES["img1"]["name"] <> "" && file_exists($img_tmp_name) ) {
$note = 'This image already exists on the server.';
}
# Checks if the image has no name
if ( $_FILES["img1"]["name"] == "" ) {
$note = 'The image supplied has no name.';
}
# Checks if the image is not a JPEG file
if ( ! ( $_FILES["img1"]["type"] == "image/jpeg" || $_FILES["img1"]["type"] == "image/pjpeg" ) ) {
$note = 'The image supplied is not JPEG.';
}
# Sets the quality of the image and the the quality of a thumbnail
$quality = 90;
$quality_th = 100;
$thumb_size = 0.25;
if ( !isset($note) ) {
if ( move_uploaded_file($_FILES["img1"]["tmp_name"], $img_tmp_name) ) {
# Creates the core image
$im = imagecreatefromjpeg($img_tmp_name);
$image_x = imageSX($im);
$image_y = imageSY($im);
$im2 = imagecreatetruecolor($image_x,$image_y);
imagecopyresampled($im2,$im,0,0,0,0,$image_x,$image_y,$image_x,$image_y);
imagejpeg($im2, $img_tmp_name, $quality);
# Checks if we can create a thumbnail, and do if so
if ( $include_thumb == 1 ) {
$im2 = imagecreatetruecolor(($image_x * $thumb_size), ($image_y * $thumb_size));
imagecopyresampled($im2,$im,0,0,0,0,($image_x * $thumb_size),($image_y * $thumb_size),$image_x,$image_y);
imagejpeg($im2, $img_tmp_name_th, $quality_th);
imagedestroy($im2);
}
imagedestroy($im);
$note = 'Image uploaded sucessfully';
}
}
}
if ( isset($note) ) {
echo '<span style="color: red; font-weight: bold;">' . $note . '<br /><br />';
}
?>
<form name="frmAddImg" method="post" enctype="multipart/form-data">
<table cellpadding="2" cellspacing="2" border="0">
<tr>
<td><b>Image</b></td>
<td><input type="file" size="30" name="img1" accept="image/jpeg"></td>
</tr>
<tr>
<td><b>Password</b></td>
<td><input type="password" size="30" name="pass"></td>
</tr>
<tr>
<td><b>Archive</b></td>
<td><select name="sltArchive" style="cursor:pointer;cursor:hand;">
<?php
for ( $x = 0; $x < count($archiveArr); $x++ ) {
echo "<option value=\"" . $archiveArr[$x] . "\">" . $archiveArr[$x] . "</option>\n";
}
?>
</select></td>
</table>
<br />
<table cellpadding="2" cellspacing="2" border="0" class="main">
<tr>
<td><input type="submit" name="submit" value="Upload" style="font-weight: bold;cursor:pointer;cursor:hand;"></td>
</tr>
</table>
</form>