Easy Image Upload

function upload($file, $storage, $folder = '/') { $types = array( 'image/jpeg' => 'jpg', 'image/jpg' => 'jpg', 'image/png' => 'png', ); if(isset($file['tmp_name'])) { if (array_key_exists($file['type'], $types)) { $tmpname = $file['tmp_name']; $filename = date('YmdHis') . '.' . bin2hex(openssl_random_pseudo_bytes(16)) . '.' . $types[$file['type']]; if (move_uploaded_file($tmpname, $storage . $folder . $filename)) { return $filename; } } } return null; }
This function get a $_FILE param, a storage path and a folder name to save a image file renaming this to a unique name.

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.