Skip to content

Instantly share code, notes, and snippets.

@flaviosilveira
Created May 26, 2014 00:28
Show Gist options
  • Save flaviosilveira/33b17ba4f648f8ff21d8 to your computer and use it in GitHub Desktop.
Save flaviosilveira/33b17ba4f648f8ff21d8 to your computer and use it in GitHub Desktop.
PHP - Image Upload
<?php
$image = $_FILES["file"];
if(preg_match("/^image\/(pjpeg|jpeg|png|gif|bmp)$/", $image["type"]))
{
// Mime Type
preg_match("/\.(gif|bmp|png|jpg|jpeg){1}$/i", $image["name"], $ext);
// File name
$name = md5(uniqid(time())) . "." . $ext[1];
// Path
$path = "../pub/" . $name;
// Save
move_uploaded_file($image["tmp_name"], $path);
// Debug
echo $name;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment