<?php
/*
UploadiFive
Copyright (c) 2012 Reactive Apps, Ronnie Garcia
*/
// Set the uplaod directory
function getExtension($str) {
        $i = strrpos($str, ".");
        if (!$i) {
            return "";
        }

        $l = strlen($str) - $i;
        $ext = substr($str, $i + 1, $l);
        return $ext;
    }
	
$uploadDir = '/phoneshop/euroasia_admin/images/gallery/';
	
// Set the allowed file extensions
$fileTypes = array('jpg', 'jpeg', 'gif', 'png'); // Allowed file extensions
	$tempFile   = $_FILES['Filedata']['tmp_name'];
	$uploadDir  = $_SERVER['DOCUMENT_ROOT'] . $uploadDir;
	
	$image = $_FILES['Filedata']['name'];
	$tempext = getExtension($image);
	$extfile = mt_rand() . "." . $tempext;
	
	$targetFile = $uploadDir . $extfile;

	// Validate the filetype
	$fileParts = pathinfo($extfile);
	if (in_array(strtolower($fileParts['extension']), $fileTypes)) {

		// Save the file
		move_uploaded_file($tempFile, $targetFile);
		echo $extfile;

	} else {

		// The file type wasn't allowed
		echo 'Invalid file type.';

	}

?>