Skip to content

Instantly share code, notes, and snippets.

@emanuelpessoaa
Forked from rogeruiz/image-upload.php
Created August 22, 2013 07:08
Show Gist options
  • Save emanuelpessoaa/6304086 to your computer and use it in GitHub Desktop.
Save emanuelpessoaa/6304086 to your computer and use it in GitHub Desktop.
<?php
// Max size in KB
define('MAX_SIZE', '100');
$errors = 0;
if (isset($_POST['Submit'])) {
$image = $_FILES['image']['name'];
if ($image) {
$fileName = strtolower(pathinfo($image, PATHINFO_FILENAME));
$ext = strtolower(pathinfo($fileName, PATHINFO_EXTENSION));
if (($ext != 'jpg') && ($ext != 'jpeg') && ($ext != 'png') && $ext != 'gif') {
echo '<h1>Unknown extension</h1>';
$errors = 1;
} else {
$imageName = time().'.'.$ext;
$newName = 'images/'.$imageName;
$copied = copy($image, $newName);
if (!$copied) {
echo '<h1>Copy Unsuccessful</h1>';
$errors = 1;
}
}
}
}
if (isset($_POST['Submit']) && !$errors) {
echo '<h1>File Uploaded Sucessfully</h1>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment