コード例 #1
0
function handleFileupload()
{
    $allowedExts = array("jpg", "jpeg", "gif", "png");
    $upload = $_FILES["qqfile"];
    $filename = $upload["name"];
    $extension = strtolower(end(explode(".", $filename)));
    if (!in_array($extension, $allowedExts)) {
        die("ACHTUNG: Scheint keine Bilddatei zu sein: {$filename}");
    }
    if ($upload["error"] > 0) {
        die("Return Code: " . $upload["error"]);
    }
    $targetFolder = targetPath($filename);
    $from = $upload["tmp_name"];
    $ext = extension($filename);
    $originalDestination = $targetFolder . "original." . $ext;
    $success = move_uploaded_file($from, $originalDestination);
    chmod($originalDestination, 0777);
    createThumbs($targetFolder, $originalDestination);
    // createThumb($destination, MEDIA_DIR."/".$prefix."thumb-".$filename);
    header("Content-Type: application/json");
    echo json_encode(array("success" => $success, "target" => $originalDestination, "data" => $upload));
}
コード例 #2
0
ファイル: index.php プロジェクト: tineo/webapoyopublicitario
<?php

$dir = dirname(__FILE__);
//echo $dir . "<br>";
$folders = scandir($dir);
foreach ($folders as $categorias) {
    //echo $categorias . "<br>";
    if ($categorias != "." && $categorias != ".." && $categorias != "index.php" && $categorias != "thumb.jpg" && $categorias != "all-thumb.gif" && $categorias != "cs-close.png") {
        $cat = $dir . "/" . $categorias;
        //echo $cat."<br/>";
        $list = scandir($cat);
        //create thumbs
        createThumbs($dir . "/" . $categorias . "", $dir . "/" . $categorias . "/thumbs", 75);
        //reducir
        resize_image($dir . "/" . $categorias . "", $dir . "/" . $categorias . "", 650);
        /*foreach ( $list as $imagen ) {
        			if ($imagen != "." && $imagen != ".." && $imagen != "index.php" && $imagen != "thumb.jpg") {
        				// echo $imagen;
        				//echo $dir . "/" . $categorias."/".$imagen."<br/>";				
        				//echo "se crearon los archivos.<br/>";
        			}
        		}*/
    }
}
function createThumbs($pathToImages, $pathToThumbs, $thumbWidth)
{
    // open the directory
    $dir = opendir($pathToImages);
    if (!is_dir($pathToThumbs)) {
        echo "se creo {$pathToThumbs}<br/>";
        if (!mkdir($pathToThumbs, 0777, true)) {
コード例 #3
0
ファイル: index2.php プロジェクト: rosahernandeza/icarus
        // continue only if this is a JPEG image
        if (strtolower($info['extension']) == 'jpg') {
            echo "Creating thumbnail for {$fname} <br />";
            // load image and get image size
            $img = imagecreatefromjpeg("{$pathToImages}{$fname}");
            $width = imagesx($img);
            $height = imagesy($img);
            // calculate thumbnail size
            $new_width = $thumbWidth;
            $new_height = floor($height * ($thumbWidth / $width));
            // create a new temporary image
            $tmp_img = imagecreatetruecolor($new_width, $new_height);
            // copy and resize old image into new image
            imagecopyresized($tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
            // save thumbnail into a file
            imagejpeg($tmp_img, "{$pathToThumbs}{$fname}");
        }
    }
    // close the directory
    closedir($dir);
}
// call createThumb function and pass to it as parameters the path
// to the directory that contains images, the path to the directory
// in which thumbnails will be placed and the thumbnail's width.
// We are assuming that the path will be a relative path working
// both in the filesystem, and through the web for links
createThumbs("upload/", "upload/thumbs/", 100);
?>

</body>
</html>
コード例 #4
0
ファイル: controller.php プロジェクト: saarmae/VR1
<?php

require_once 'functions.php';
startSession();
connect_db();
create_tables();
setupImageFolders();
createThumbs();
setupPictures();
if (!empty($_GET)) {
    if ($_GET["mode"] != "") {
        $mode = $_GET["mode"];
    }
} else {
    $mode = "index";
}
require_once 'head.php';
switch ($mode) {
    case 'index':
        viewFront();
        break;
    case 'gallery':
        viewGallery();
        break;
    case 'login':
        viewLogin();
        break;
    case 'register':
        viewRegister();
        break;
    case 'upload':
コード例 #5
0
ファイル: resize.php プロジェクト: peteplays/thumbmaker
        $info = pathinfo($pathToImages . $fname);
        // continue only if this is a JPEG image
        if (strtolower($info['extension']) == 'jpg') {
            echo "Creating thumbnail for {$fname} <br />";
            // load image and get image size
            $img = imagecreatefromjpeg("{$pathToImages}{$fname}");
            $width = imagesx($img);
            $height = imagesy($img);
            // calculate thumbnail size
            $new_width = $thumbWidth;
            $new_height = floor($height * ($thumbWidth / $width));
            // create a new temporary image
            $tmp_img = imagecreatetruecolor($new_width, $new_height);
            // copy and resize old image into new image
            imagecopyresized($tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
            // save thumbnail into a file
            imagejpeg($tmp_img, "{$pathToThumbs}{$fname}", 100);
            $pic_data = 'ORG: H:' . $height . ' W: ' . $width . '<br> NEW: H:' . $new_height . ' W: ' . $new_width . '<br><br>';
            echo $pic_data;
        }
    }
    // close the directory
    closedir($dir);
}
// call createThumb function and pass to it as parameters the path
// to the directory that contains images, the path to the directory
// in which thumbnails will be placed and the thumbnail's width.
// We are assuming that the path will be a relative path working
// both in the filesystem, and through the web for links
createThumbs("uploads/", "uploads/thumbs/", 200);
コード例 #6
0
ファイル: upload.php プロジェクト: beemoon/signage
     * Traitement des fichiers PDF dans le repertoire temp
     * avant suppression 
     */
    if ($path_parts['extension'] == "pdf") {
        $_type[0] = 'image';
        if (!is_dir($targetPath . $ds . $_type[0])) {
            mkdir($targetPath . $ds . $_type[0], 0777);
            chmod($targetPath . $ds . $_type[0], 0777);
        }
        $targetFileName = $path_parts['filename'] . '.jpg';
        pdftojpg($targetFile, $targetPath . $ds . $_type[0] . $ds . $targetFileName);
        $slideInf['path'] = $_type[0];
        // rename to unique filename (timestamp)
        //$targetFile = $targetPath. $ds . $_type[0] . $ds . $uniqueID . '.jpg';
        //rename($targetPath. $ds . $_type[0] . $ds . $path_parts['filename'] . '.jpg',$targetFile);
        createThumbs($targetPath . $ds . $_type[0] . $ds . $targetFileName, 266.7, 1.778);
    }
    // ajoute la description du slide
    $slideInf['description'] = nl2br(htmlentities($_POST['descriptif'], ENT_QUOTES));
    chmod($targetFile, 0777);
    /* On vide le repertoire temp et on le supprime */
    if (is_dir($targetPath . $ds . 'temp') && count(glob($targetPath . $ds . 'temp' . $ds . '*')) != 0) {
        array_map('unlink', glob($targetPath . $ds . 'temp' . $ds . '*'));
        rmdir($targetPath . $ds . 'temp');
    }
    addToSlideDB($targetFileName, $slideInf, $storeFolder . $ds . 'slideDB.ini');
}
/* fichier de log pour controle */
//file_put_contents($targetPath. $ds . $_type[0] . $ds . $path_parts['filename'].'.txt', print_r($slideInf,true));
//file_put_contents($storeFolder. $ds .'debug.ini',print_r($slideInf,true));
/* génération des slides */
コード例 #7
0
ファイル: admin.php プロジェクト: mrj0909/sf
 public function add_ban_image()
 {
     $time = time() . rand();
     $logo = array('file' => $_FILES["userfile"], 'new_name' => $time . '_o', 'dst_path' => $this->config->item('ban_image_path'));
     $logo_response = upload_original($logo);
     $src_path = $this->config->item('ban_image_path') . $logo_response['file_name'];
     $ext = $logo_response['file_ext'];
     //echo $this->config->item('ban_image_path');
     createThumbs($src_path, $this->config->item('ban_image_path'), $time . "_s." . $ext, $ext, 100);
     createThumbs($src_path, $this->config->item('ban_image_path'), $time . "_l." . $ext, $ext, 250);
     /*  $logo_thumbs = array(
             array(
                 'src_path' => $src_path,
                 'dst_path' => $this->config->item('ban_image_path'),
                 'image_x' => $this->config->item('ban_image_large_x'),
                 'image_y' => $this->config->item('ban_image_large_y'),
                 'image_ratio' => FALSE,
                 'image_ratio_fill' => FALSE,
                 'new_name' => $time . '_l'
             ),
             array(
                 'src_path' => $src_path,
                 'dst_path' => $this->config->item('ban_image_path'),
                 'image_x' => $this->config->item('ban_image_small_x'),
                 'image_y' => $this->config->item('ban_image_small_y'),
                 'image_ratio' => TRUE,
                 'image_ratio_fill' => TRUE,
                 'new_name' => $time . '_s'
             )
         );
         foreach ($logo_thumbs as $logo_thumb) {
             //upload_resized_images($logo_thumb);
         }*/
     echo json_encode(array('name' => $time, 'ext' => $logo_response['file_ext'], 'imagename' => other_asset_url($time . '_s.' . $logo_response['file_ext'], '', 'uploads/images/banners')));
 }
コード例 #8
0
ファイル: ajax_upload.php プロジェクト: swuit/swuit-q2a
                $withoutExt = preg_replace("/\\.[^.\\s]{3,4}\$/", "", $fileName);
                for ($i = 2; file_exists($output_dir . $withoutExt . '-' . $i . '.' . $exts); $i++) {
                }
                $fileName = $withoutExt . '-' . $i . '.' . $exts;
            }
            // put file in server
            move_uploaded_file($_FILES["myfile"]["tmp_name"], $output_dir . $fileName);
            // create thumbnail
            list($originalWidth, $originalHeight) = getimagesize($output_dir . $fileName);
            $new_width = 320;
            $new_height = floor($originalWidth / $new_width * $originalHeight);
            // create thumbnail for lists
            $exts = substr(strrchr($fileName, '.'), 1);
            $withoutExt = preg_replace("/\\.[^.\\s]{3,4}\$/", "", $fileName);
            $thumbnailName = $withoutExt . '_.' . $exts;
            createThumbs($output_dir . $fileName, $output_dir . $thumbnailName, 320);
            $ret[] = $dir_name . $fileName;
            echo json_encode($ret);
            die;
        }
    }
    // if there was an error and file was not successfull uploaded return the error.
    echo json_encode($error);
}
function createThumbs($pathToImages, $pathToThumbs, $thumbWidth)
{
    $quality = 100;
    $info = getimagesize($pathToImages);
    // load image and get image size
    if ($info[2] == IMAGETYPE_JPEG) {
        $image = imagecreatefromjpeg("{$pathToImages}");
コード例 #9
0
ファイル: helpers.php プロジェクト: matthiku/cSpot
/**
 * temporary job...
 */
function createThumbsForAll()
{
    chdir('public/' . config('files.uploads.webpath'));
    // create list of current files in images folder
    // (exclude thumb_... or mini_...)
    $files = glob('*.*');
    // loop through each file
    foreach ($files as $key => $imgfile) {
        // is it already minified?
        $prefix = explode('-', $imgfile);
        if ($prefix[0] == 'mini' || $prefix[0] == 'thumb') {
            continue;
        }
        // check if thumb_... or mini_... already exists for this file
        if (file_exists('thumb-' . $imgfile) && file_exists('mini-' . $imgfile)) {
            continue;
        }
        // create thumb and mini copy of this file
        Log::info("Creating thumbs for {$imgfile}:\n");
        createThumbs('.', $imgfile);
    }
    // make sure user 'www-data' has access rights to all files
    $files = glob('*.*');
    foreach ($files as $key => $value) {
        chmod($value, 0777);
    }
}
コード例 #10
0
ファイル: upload_image.php プロジェクト: rhondamoananui/ec
    }
    // quality is a value from 0 (worst) to 100 (best)
    imagejpeg($imageTmp, $outputImage, $quality);
    imagedestroy($imageTmp);
    return 1;
}
if (isset($_POST['id']) && isset($_SESSION['loggedId'])) {
    if ($_FILES["picture"]["error"] > 0) {
        echo "error";
    } else {
        if ($_FILES["picture"]["type"] == "image/gif" || $_FILES["picture"]["type"] == "image/jpeg" || $_FILES["picture"]["type"] == "image/jpg" || $_FILES["picture"]["type"] == "image/pjpeg" || $_FILES["picture"]["type"] == "image/x-png" || $_FILES["picture"]["type"] == "image/png") {
            if ($_FILES["picture"]["size"] < 3145728) {
                if (move_uploaded_file($_FILES["picture"]["tmp_name"], $root . "/uploads/" . $_FILES["picture"]["name"])) {
                    if (convertImageToJpg($root . "/uploads/" . $_FILES["picture"]["name"], $root . '/uploads/temp' . $_POST['id'] . '.jpg', 100)) {
                        if (unlink($root . "/uploads/" . $_FILES["picture"]["name"])) {
                            if (createThumbs($root . '/uploads/temp' . $_POST['id'] . '.jpg', $root . '/images/' . $_POST['id'] . '.jpg', 700)) {
                                $finished_image = imagecreatefromjpeg($root . '/images/' . $_POST['id'] . '.jpg');
                                $width = imagesx($finished_image);
                                $height = imagesy($finished_image);
                                if (isset($_POST['banner']) && $_POST['banner'] == 1) {
                                    $banner = 1;
                                    $QL->query('DELETE FROM images WHERE user='******'loggedId'] . ' AND banner=1');
                                } else {
                                    $banner = 0;
                                }
                                $result = $QL->query('SELECT COUNT(*) AS ofMain FROM images WHERE user='******'loggedId'] . ' AND main=1');
                                $number = $result->fetch_assoc();
                                if ($banner == 0 && $number['ofMain'] == 0) {
                                    $main = 1;
                                } else {
                                    $main = 0;
コード例 #11
0
ファイル: create_thumbs.php プロジェクト: laiello/longjohn
    $output .= "</table>";
    $output .= "<?require_once 'footer.php';?>";
    // open the file
    $fhandle = fopen("{$galleryPage}", "w");
    // write the contents of the $output variable to the file
    fwrite($fhandle, $output);
    // close the file
    fclose($fhandle);
}
require_once "header.php";
echo "<form action='create_thumbs.php' method='post'>";
echo "Gallery Directory:<input type='text' name='search1' value=''>";
echo "Gallery Name:<input type='text' name='gallery' value=''>";
echo "<input type='submit' name='go' value='go' /><br>";
if (!isset($_POST['go'])) {
} else {
    $gallery = $_POST['gallery'] . ".php";
    // call createThumb function and pass to it as parameters the path
    // to the directory that contains images, the path to the directory
    // in which thumbnails will be placed and the thumbnail's width.
    // We are assuming that the path will be a relative path working
    // both in the filesystem, and through the web for links
    createThumbs("pics/" . $_POST['search1'] . "/", "thumbs/" . $_POST['search1'] . "/", 100);
    // call createGallery function and pass to it as parameters the path
    // to the directory that contains images and the path to the directory
    // in which thumbnails will be placed. We are assuming that
    // the path will be a relative path working
    // both in the filesystem, and through the web for links
    createGallery("pics/" . $_POST['search1'] . "/", "thumbs/" . $_POST['search1'] . "/", "{$gallery}");
}
require_once "footer.php";
コード例 #12
0
ファイル: creaThumb.php プロジェクト: ArcTeam/site
    while (false !== ($fname = readdir($dir))) {
        // parse path for the extension
        $info = pathinfo($pathToImages . $fname);
        // continue only if this is a JPEG image
        if (strtolower($info['extension']) == 'png') {
            echo "Creating thumbnail for {$fname} <br />";
            // load image and get image size
            $img = imagecreatefrompng("{$pathToImages}{$fname}");
            $width = imagesx($img);
            $height = imagesy($img);
            // calculate thumbnail size
            $new_width = $thumbWidth;
            $new_height = floor($height * ($thumbWidth / $width));
            // create a new temporary image
            $tmp_img = imagecreatetruecolor($new_width, $new_height);
            // copy and resize old image into new image
            imagecopyresized($tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
            // save thumbnail into a file
            imagepng($tmp_img, "{$pathToThumbs}{$fname}");
        }
    }
    // close the directory
    closedir($dir);
}
// call createThumb function and pass to it as parameters the path
// to the directory that contains images, the path to the directory
// in which thumbnails will be placed and the thumbnail's width.
// We are assuming that the path will be a relative path working
// both in the filesystem, and through the web for links
createThumbs("../img/servizi/", "../img/servizi/thumbs/", 250);
コード例 #13
0
ファイル: index.php プロジェクト: tineo/webapoyopublicitario
    $dir = opendir($pathToImages);
    // loop through it, looking for any/all JPG files:
    while (false !== ($fname = readdir($dir))) {
        // parse path for the extension
        $info = pathinfo($pathToImages . $fname);
        // continue only if this is a JPEG image
        if (strtolower($info['extension']) == 'jpg') {
            //echo "Se redujo la imagen  {$fname} <br />";
            // load image and get image size
            $img = imagecreatefromjpeg("{$pathToImages}" . "/" . "{$fname}");
            $width = imagesx($img);
            $height = imagesy($img);
            // calculate thumbnail size
            $new_width = $thumbWidth;
            $new_height = floor($height * ($thumbWidth / $width));
            // create a new temporary image
            $tmp_img = imagecreatetruecolor($new_width, $new_height);
            // copy and resize old image into new image
            imagecopyresized($tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
            // save thumbnail into a file
            imagejpeg($tmp_img, "{$pathToThumbs}" . "/" . "{$fname}");
            //echo "$pathToThumbs" . "/" . "$fname<br/>";
        }
    }
    // close the directory
    closedir($dir);
}
$dir = dirname(__FILE__);
echo $dir;
createThumbs($dir, $dir, 150);
コード例 #14
0
            echo "<tr><td></td></tr>";
        } else {
            echo "<tr><th colspan='2'><h3>" . $_FILES["new{$i}"]["name"] . "</h3></th>\n\t\t\t\t\t\t</tr><tr><td>Upload: </td><td>" . $_FILES["new{$i}"]["name"] . "</td></tr>";
            echo "<tr><td>Type: </td><td>" . $_FILES["new{$i}"]["type"] . "</td></tr>";
            if ($_FILES["new{$i}"]["size"] >= 1024000) {
                echo "<tr><td>File Size is Greater than 1 MB</td></tr>";
            } else {
                if (file_exists("Image/" . $_FILES["new{$i}"]["name"])) {
                    echo "<tr><td>" . $_FILES["new{$i}"]["name"] . " already exists. </td></tr>";
                } else {
                    if ($_FILES["new{$i}"]["size"] <= 0) {
                        echo "<tr><td>File Size is Too Low</td></tr>";
                    } else {
                        $g_pic = $_FILES["new{$i}"]["name"];
                        if ($i === 0) {
                            mysql_query("INSERT INTO gname(GName,Gpic) VALUES('" . $gallery_name . "','" . $g_pic . "')") or die(mysql_error());
                        }
                        move_uploaded_file($_FILES["new{$i}"]["tmp_name"], "Image/" . $_FILES["new{$i}"]["name"]);
                        echo "<tr><td>Size : </td><td>" . $_FILES["new{$i}"]["size"] / "1024" . " KB </td></tr>";
                        createThumbs("Image/", "Thumb/", 100);
                        createGallery("Image/", "Thumb/");
                    }
                }
            }
        }
    }
}
echo "<tr><td>Uploading Successfull See Gallery</td></tr></table></center>";
?>
 
コード例 #15
0
ファイル: index.php プロジェクト: kleopatra999/PHPhoto
    $ctrl_bar['ena'] = TRUE;
    $dir_nav['prefs_ena'] = FALSE;
}
/**
* Determine if we need a display area.
*/
if (!empty($site_lnk_url) || $qdig_homelink['ena'] == FALSE || !empty($imgs)) {
    $display_area = TRUE;
} else {
    $display_area = FALSE;
}
/**
* Create thumbnail image(s) if necessary.
*/
if ($thmb_onfly == FALSE) {
    $thumbs_msg = createThumbs($cnvrt_thmb);
}
/**
* Create alternate image sizes.
*/
$resize_msg = '';
if ($disp_size['0'] == TRUE && ($cnvrt_alt['indiv'] == FALSE || $upr_nav['sizer'] == TRUE || $lwr_nav['sizer'] == TRUE || $reqd_img_size == $cnvrt_size['0']['label'])) {
    $resize_msg .= resizeImage($cnvrt_size['0']);
}
if ($disp_size['1'] == TRUE && ($cnvrt_alt['indiv'] == FALSE || $upr_nav['sizer'] == TRUE || $lwr_nav['sizer'] == TRUE || $reqd_img_size == $cnvrt_size['1']['label'])) {
    $resize_msg .= resizeImage($cnvrt_size['1']);
}
if ($disp_size['2'] == TRUE && ($cnvrt_alt['indiv'] == FALSE || $upr_nav['sizer'] == TRUE || $lwr_nav['sizer'] == TRUE || $reqd_img_size == $cnvrt_size['2']['label'])) {
    $resize_msg .= resizeImage($cnvrt_size['2']);
}
if ($disp_size['3'] == TRUE && ($cnvrt_alt['indiv'] == FALSE || $upr_nav['sizer'] == TRUE || $lwr_nav['sizer'] == TRUE || $reqd_img_size == $cnvrt_size['3']['label'])) {
コード例 #16
0
ファイル: get_metas_exif_img.php プロジェクト: rhertzog/lcs
$p == "finder.png" ? $url_ = $file : ($url_ = "../" . $_POST['file']);
$p == "finder.png" ? $user_ = $user : ($user_ = $_POST['user']);
$pat = array();
$pat[0] = '/core/';
$pat[1] = '/thumbs/';
$pat[2] = '/\\/home\\//';
$pat[3] = '/public_html\\//';
$rep = array();
$rep[0] = '..';
$rep[1] = '';
$rep[2] = '../~';
$rep[3] = '';
$url = preg_replace($pat, $rep, $url_);
$p == "finder.png" ? $urlImg = preg_replace("/\\.\\./", "", $url) : ($urlImg = preg_replace("/\\.\\.\\//", "", $url_));
$path_img = pathinfo($url);
createThumbs("../images/misc/", "../images/misc/thumbs/", 150);
/*
				echo $path_img['dirname'], "\n";
				echo $path_img['basename'], "\n";
				echo $path_img['extension'], "\n";
*/
echo "<div class=\"ui-finder-file-preview file-preview\">" . "<p class=\"ui-finder-image content_updown down\">" . "<span class=\"triangle_updown down\">Pr&eacute;visualiser</span>" . "<img src=\"" . $urlImg . "\"  id=\"vign_wlpper\" class=\"float_left finder_img\" /></p>";
echo "<div class=\"img_infos\"><a name=\"moreInfosFile\"></a><h3 class=\"img_name\">" . ucfirst(preg_replace('/_/', ' ', $path_img['filename'])) . "</h3>" . "<em>" . $path_img['filename'] . "." . $path_img['extension'] . "</em>";
// depuis PHP 5.2.0
//			$p=="finder.png"? $padd="padding-left:175px;": $padd="padding-left:0;";
$padd = "padding-left:0;";
$res .= "<div style=\"" . $padd . "\">";
//			$MetaTags=alt_stat(preg_replace("/core/","..",$url));
//			$eXimg=exif_read_data(preg_replace("/core/","..",$url));
$MetaTags = alt_stat(preg_replace("/core/", "..", preg_replace("/thumbs/", "", preg_replace("/\\.\\.\\/~" . $user_ . "/", "/home/" . $user_ . "/public_html", $url_))));
$ext = pathinfo($url, PATHINFO_EXTENSION);
コード例 #17
0
ファイル: upload.lib.php プロジェクト: ksb1712/pragyan
/**
 * Saves the uploaded file.
 * @param $moduleComponentId page_modulecomponentid.
 * @param $moduleName The module which is calling this function.
 * @param $userId The user uploading the file.
 * @param $uploadFileName The name of the uploaded file.
 * @param $tempFileName The temporary file name of the uploaded file.
 * @param $uploadFileType The file type of the uploaded file.
 * @return $uploadFilaName The name of the file uploaded.
 *
 */
function saveUploadedFile($moduleComponentId, $moduleName, $userId, $uploadFileName, $tempFileName, $uploadFileType, $uploadDir)
{
    $query = 'SELECT MAX(`upload_fileid`) FROM `' . MYSQL_DATABASE_PREFIX . 'uploads`';
    $result = mysql_query($query) or die(mysql_error() . 'upload.lib L:131');
    $row = mysql_fetch_row($result);
    $upload_fileid = 1;
    if (!is_null($row[0])) {
        $upload_fileid = $row[0] + 1;
    }
    $finalName = str_pad($upload_fileid, 10, '0', STR_PAD_LEFT) . '_' . $uploadFileName;
    ///Checking for inconsistency in the uploaded file names.
    if (strpbrk($uploadFileName, '%#&')) {
        displayerror("(\") , ( % ) and ( & ) are not allowed in the file name.");
        return false;
    }
    $duplicateCheckQuery = "SELECT * FROM `" . MYSQL_DATABASE_PREFIX . "uploads` " . "WHERE `page_modulecomponentid` = '{$moduleComponentId}' AND `page_module` = '{$moduleName}'" . " AND upload_filename = '{$uploadFileName}'";
    $duplicateCheckResult = mysql_query($duplicateCheckQuery);
    /// Checking for duplicate entry of the file.
    if (mysql_num_rows($duplicateCheckResult) >= 1) {
        displayerror("A file with the name {$uploadFileName} already exists. Please use a different filename.");
        return false;
    }
    $query = 'INSERT INTO `' . MYSQL_DATABASE_PREFIX . 'uploads` ' . '(`page_modulecomponentid`, `page_module`, `upload_fileid`, `upload_filename`, `upload_filetype`, `user_id`) ' . "VALUES ('{$moduleComponentId}', '{$moduleName}', '{$upload_fileid}', " . "'" . mysql_escape_string($uploadFileName) . "', '{$uploadFileType}', '{$userId}')";
    mysql_query($query) or die(mysql_error() . "upload.lib L:158<br />");
    /// If galery create thumbnail and store in the database.
    if ($moduleName == "gallery") {
        $thumb_upload_fileid = $upload_fileid + 1;
        $thumb_name = "thumb_" . $uploadFileName;
        $thumb_finalName = str_pad($thumb_upload_fileid, 10, '0', STR_PAD_LEFT) . '_' . $thumb_name;
        $thmb = createThumbs($tempFileName, "{$uploadDir}/{$moduleName}/{$thumb_finalName}", 136);
        if (!$thmb) {
            displayerror("Unable to generate thumbnail / open file. Try later");
            return false;
        }
        $query = 'INSERT INTO `' . MYSQL_DATABASE_PREFIX . 'uploads` ' . '(`page_modulecomponentid`, `page_module`, `upload_fileid`, `upload_filename`, `upload_filetype`, `user_id`) ' . "VALUES ('{$moduleComponentId}', '{$moduleName}', '{$thumb_upload_fileid}', " . "'" . mysql_escape_string($thumb_name) . "', '{$uploadFileType}', '{$userId}')";
        mysql_query($query) or die(mysql_error() . "upload.lib L:163<br />");
    }
    move_uploaded_file($tempFileName, "{$uploadDir}/{$moduleName}/{$finalName}");
    return $uploadFileName;
}