Example #1
0
<?php

// Include common functions and declarations
require_once "../../../../include/common.php";
// Check if user
if (!$login->isUser()) {
    $login->printLoginForm();
    exit;
}
// Initialize variables
$file = "";
$fileText = "";
// Upload file
if (!empty($_FILES["file"]["name"])) {
    $extension = convertToLowercase(substr(strrchr($_FILES["file"]["name"], "."), 1));
    // Insert into file database
    $dbi->query("INSERT INTO " . fileTableName . "(folderId,name,type,size) VALUES('" . pageUploadFolder . "'," . $dbi->quote($_FILES["file"]["name"]) . "," . $dbi->quote($_FILES["file"]["type"]) . "," . $dbi->quote($_FILES["file"]["size"]) . ")");
    $id = $dbi->getInsertId();
    if (!empty($id)) {
        // Move uploaded file
        move_uploaded_file($_FILES["file"]["tmp_name"], filePath . "/" . $id . "." . $extension);
        // Save file name
        $file = scriptUrl . "/" . folderFiles . "/" . fileFilesGetFile . "?fileId={$id}";
        $fileText = !empty($_POST["uploadFileDescription"]) ? $_POST["uploadFileDescription"] : $_FILES["file"]["name"];
    }
} else {
    if (!empty($_POST["fileUrl"])) {
        $file = $_POST["fileUrl"];
        $fileText = !empty($_POST["uploadFileDescription"]) ? $_POST["uploadFIleDescription"] : (!empty($_POST["fileName"]) ? $_POST["fileName"] : "");
    }
}
Example #2
0
 /**
  * Get type icon for the current file.
  * @return url to icon.
  */
 function getIconUrl()
 {
     $extension = convertToLowercase($this->getFileExtension());
     if (!file_exists(scriptPath . "/" . folderUploadedFiles . "/" . $this->id . "." . $this->getFileExtension($this->name))) {
         return iconUrl . "/warning.gif";
     } else {
         if ($extension == "bmp" || $extension == "gif" || $extension == "jpg" || $extension == "png") {
             return iconUrl . "/image.gif";
         } else {
             if ($extension == "mp3") {
                 return iconUrl . "/audio.gif";
             } else {
                 if ($extension == "txt" || $extension == "rtf" || $extension == "doc" || $extension == "pdf" || $extension == "odt") {
                     return iconUrl . "/document.gif";
                 }
             }
         }
     }
     return iconUrl . "/page.gif";
 }
Example #3
0
// Check if user
if (!$login->isUser()) {
    $login->printLoginForm();
    exit;
}
// Initialize variables
$imageFile = "";
$imageText = "";
// Upload picture
if (!empty($_FILES["file"]["name"])) {
    $extension = substr(strrchr($_FILES["file"]["name"], "."), 1);
    if ($extension == "gif" || $extension == "jpg" || $extension == "jpeg" || $extension == "JPEG" || $extension == "GIF" || $extension == "JPG" || $extension == "PNG" || $extension == "png") {
        if ($extension == "jpeg" || $extension == "JPEG") {
            $extension = "jpg";
        }
        $extension = convertToLowercase($extension);
        // Resize file if not webmaster
        if (!$login->isWebmaster()) {
            $dimensions = getImageDimensions($_FILES["file"]["tmp_name"]);
            $width = 600;
            $ratio = $width / $dimensions[0];
            $height = $dimensions[1] * $ratio;
            if ($dimensions[0] > $width) {
                resizeToFile($_FILES["file"]["tmp_name"], $width, $height, $_FILES["file"]["tmp_name"], 100);
            }
        }
        // Insert into file database
        $dbi->query("INSERT INTO " . fileTableName . "(folderId,name,type,size) VALUES('" . (!empty($_POST["imageTargetFolder"]) ? $_POST["imageTargetFolder"] : pageUploadFolder) . "'," . $dbi->quote($_FILES["file"]["name"]) . "," . $dbi->quote($_FILES["file"]["type"]) . "," . $dbi->quote($_FILES["file"]["size"]) . ")");
        $id = $dbi->getInsertId();
        if (!empty($id)) {
            // Get thumbnail width