Skip to content

Instantly share code, notes, and snippets.

@enopanen
Created December 5, 2013 17:07
Show Gist options
  • Save enopanen/7809280 to your computer and use it in GitHub Desktop.
Save enopanen/7809280 to your computer and use it in GitHub Desktop.
Photo Uploader resides in /DOCUMENT_ROOT/admin/index.php and uses imagick
<?php
if(isset($_POST['addImage'])) {
//echo "<pre>" . print_r($_FILES, true) . "</pre>" ;
if(isset($_FILES['gMainImg'])) {
$tmpFile = $_FILES["gMainImg"]["tmp_name"];
$fileName = "../images/gallery/" .time(). ".jpg" ;
echo getcwd();
list($width, $height) = getimagesize($tmpFile);
// check if the file is really an image
if ($width == null && $height == null) {
header("Location: http://www.americanlabdesign.com/admin/index.php?whError=true");
return;
}
// resize if necessary
if ($width >= 400 && $height >= 400) {
$image = new Imagick($tmpFile);
$image->thumbnailImage(65, 65);
$image->writeImage($fileName);
}
else {
if(move_uploaded_file($tmpFile, $fileName)) {
die("success");
}
else {
die("wtf");
}
}
header("Location: http://www.americanlabdesign.com/admin/index.php?imageuploaded=success");
exit;
}//end if
}//end if
?>
<form id="galleryForm" action="/admin/index.php" method="post" enctype="multipart/form-data" >
<h2 style="font-size:20px;font-weight:bold;" >Add New Image</h2>
<br><br>
<label style="font-size:16px;" class="fileInput" >Image Name:</label> <input type="text" name="gName" class="fileInput" >
<div style="clear:left;" ></div>
<br><br>
<label style="font-size:16px;" class="fileInput" >Select Image:</label> <input type="file" name="gMainImg" class="fileInput" >
<div style="clear:left;" ></div>
<br><br>
<input style="float:right;" type='submit' value="submit" name="addImage" >
<div style="clear:right;" ></div>
</form>
<?php
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment