Example #1
0
File: file.php Project: lmcro/fcms
/**
 * printUpImage 
 * 
 * @return void
 */
function printUpImage()
{
    $filename = $_GET['u'];
    $filename = basename($filename);
    $path = getUploadsAbsolutePath() . 'upimages/' . $filename;
    // Make sure photo file exists
    if (!file_exists($path) || !is_file($path)) {
        logError(__FILE__ . ' [' . __LINE__ . '] No image [' . $filename . '] found in directory [' . $path . '].');
        header('HTTP/1.0 404 Not Found');
        return;
    }
    $info = getimagesize($path);
    header("Cache-control: public, no-cache;");
    header("Content-type: " . $info['mime']);
    readfile($path);
    exit;
}
Example #2
0
File: photo.php Project: lmcro/fcms
// Get photo path
// External
if ($photo['filename'] == 'noimage.gif' && $photo['external_id'] != null) {
    $path = $photo[$size];
    if (!fopen($path, 'r')) {
        logError(__FILE__ . ' [' . __LINE__ . '] No photo found remotely [' . $path . '] for photo id [' . $id . '].');
        header('HTTP/1.0 404 Not Found');
        return;
    }
} else {
    $prefix = '';
    if ($size == 'thumbnail') {
        $prefix = 'tb_';
    } elseif ($size == 'full' && $galleryObj->usingFullSizePhotos()) {
        $prefix = 'full_';
    }
    $filename = basename($photo['filename']);
    $userId = (int) $photo['user'];
    $path = getUploadsAbsolutePath() . 'photos/member' . $userId . '/' . $prefix . $filename;
    // Make sure photo file exists
    if (!file_exists($path) || !is_file($path)) {
        logError(__FILE__ . ' [' . __LINE__ . '] No photo found in directory [' . $path . '] for photo id [' . $id . '].');
        header('HTTP/1.0 404 Not Found');
        return;
    }
}
$info = getimagesize($path);
header("Cache-control: public, no-cache;");
header("Content-type: " . $info['mime']);
readfile($path);
exit;
Example #3
0
 /**
  * displayEditThumbnailSubmit 
  * 
  * @return void
  */
 function displayEditThumbnailSubmit()
 {
     $id = (int) $_POST['id'];
     $category = (int) $_POST['category'];
     $thumbnail = 'no_recipe.jpg';
     $uploadsPath = getUploadsAbsolutePath();
     // Upload Recipe Image
     if (isset($_FILES['thumbnail']) && $_FILES['thumbnail']['name'] && $_FILES['thumbnail']['error'] < 1) {
         $this->fcmsImage->destination = $uploadsPath . 'upimages/';
         $this->fcmsImage->uniqueName = true;
         $thumbnail = $this->fcmsImage->upload($_FILES['thumbnail']);
         if ($this->fcmsImage->error == 1) {
             $this->displayHeader();
             echo '
 <p class="error-alert">
     ' . sprintf(T_('Thumbnail [%s] is not a supported type. Thumbnails must be of type (.jpg, .jpeg, .gif, .bmp or .png).'), $this->img->name) . '
 </p>';
             $this->displayFooter();
             return;
         }
         $this->fcmsImage->resize(100, 100);
         if ($this->fcmsImage->error > 0) {
             $this->displayHeader();
             echo '
 <p class="error-alert">
     ' . T_('There was an error uploading your thumbnail.') . '
 </p>';
             $this->displayFooter();
             return;
         }
     }
     $sql = "UPDATE `fcms_recipes` \n                SET `thumbnail` = ?\n                WHERE `id` = ?";
     $params = array($thumbnail, $id);
     if (!$this->fcmsDatabase->update($sql, $params)) {
         $this->displayHeader();
         $this->fcmsError->displayError();
         $this->displayFooter();
         return;
     }
     header("Location: recipes.php?category={$category}&id={$id}");
 }
Example #4
0
 /**
  * uploadPhoto 
  * 
  * Uploads a photo to the /uploads/photos/memberX/ directory where x is the user id.
  * Adds photo info to the db, creates a thumbnail, resizes middle sized photo 
  * and rotates the photo if desired.
  *
  * @param   int     $category
  * @param   array   $photo                  array of uploaded photo data
  * @param   string  $caption
  * @param   string  $rotateoptions
  * @param   boolean $overrideMemoryWarning
  * @param   int     $thumb_max_width        defaults to 150px
  * @param   int     $thumb_max_height       defaults to 150px
  * @param   int     $main_max_width         defaults to 600px
  * @param   int     $main_max_height        defaults to 600px
  *
  * @return  int
  */
 function uploadPhoto($category, $photo, $caption, $rotateoptions, $overrideMemoryWarning = false, $thumb_max_width = 150, $thumb_max_height = 150, $main_max_width = 600, $main_max_height = 600)
 {
     // Valid photo?
     if ($photo['size'] <= 0) {
         echo '
         <p class="error-alert">' . T_('Photo is corrupt or missing.') . '</p>';
         return false;
     }
     $uploadsPath = getUploadsAbsolutePath();
     // Create new directory if needed
     if (!file_exists($uploadsPath . 'photos/member' . $this->fcmsUser->id)) {
         mkdir($uploadsPath . 'photos/member' . $this->fcmsUser->id);
     }
     // Insert new photo record
     $sql = "INSERT INTO `fcms_gallery_photos`\n                    (`date`, `caption`, `category`, `user`)\n                VALUES\n                    (NOW(), ?, ?, ?)";
     $params = array($caption, $category, $this->fcmsUser->id);
     $id = $this->fcmsDatabase->insert($sql, $params);
     if ($id === false) {
         $this->fcmsError->displayError();
         return false;
     }
     // Temporarily set name so we can get extension, then change name below
     $this->fcmsImage->name = $photo['name'];
     $this->fcmsImage->getExtension();
     // Setup the array of photos that need uploaded
     $upload_photos = array('main' => array('resize' => true, 'prefix' => '', 'width' => $main_max_width, 'height' => $main_max_height), 'thumb' => array('resize' => true, 'prefix' => 'tb_', 'width' => $thumb_max_width, 'height' => $thumb_max_height));
     if ($this->usingFullSizePhotos()) {
         $upload_photos['full'] = array('resize' => false, 'prefix' => 'full_', 'width' => 0, 'height' => 0);
     }
     // Loop through each photo that needs uploaded
     foreach ($upload_photos as $key => $value) {
         $resize = $upload_photos[$key]['resize'];
         $prefix = $upload_photos[$key]['prefix'];
         $width = $upload_photos[$key]['width'];
         $height = $upload_photos[$key]['height'];
         // Setup image upload settings
         $this->fcmsImage->name = $prefix . $id . '.' . $this->fcmsImage->extension;
         $this->fcmsImage->destination = $uploadsPath . 'photos/member' . $this->fcmsUser->id . '/';
         $this->fcmsImage->resizeSquare = $key == 'thumb' ? true : false;
         if ($key == 'main') {
             // Update photo record
             $sql = "UPDATE `fcms_gallery_photos` \n                        SET `filename` = ?\n                        WHERE `id` = ?";
             if (!$this->fcmsDatabase->update($sql, array($this->fcmsImage->name, $id))) {
                 $this->fcmsError->displayError();
                 return false;
             }
         }
         // Upload photo
         $this->fcmsImage->upload($photo);
         if ($this->fcmsImage->error == 1) {
             echo '
             <p class="error-alert">
                 ' . sprintf(T_('Photo [%s] is not a supported photo type.  Photos must be of type (.jpg, .jpeg, .gif, .bmp or .png).'), $this->fcmsImage->name) . '
             </p>';
             return false;
         }
         // Rotate
         if ($rotateoptions == 'left') {
             $this->fcmsImage->rotate(90);
         } elseif ($rotateoptions == 'right') {
             $this->fcmsImage->rotate(270);
         }
         // Resize
         if ($resize) {
             $this->fcmsImage->resize($width, $height);
         }
         // Errors?
         if ($this->fcmsImage->error > 0) {
             $this->handleImageErrors($id);
             return false;
         }
     }
     // Get photo source
     if (defined('UPLOADS')) {
         $photoSrc = GALLERY_PREFIX . 'photo.php?id=' . $id . '&amp;size=thumbnail';
     } else {
         $photoSrc = URL_PREFIX . 'uploads/photos/member' . $this->fcmsUser->id . '/' . $this->fcmsImage->name;
     }
     echo '
         <p class="ok-alert">
             <b>' . T_('The following photo was added successfully.') . '</b><br/><br/>
             <img src="' . $photoSrc . '" alt="' . cleanOutput($caption) . '"/>
         </p>';
     return $id;
 }
Example #5
0
 /**
  * displayDeleteDocumentSubmit 
  * 
  * @return void
  */
 function displayDeleteDocumentSubmit()
 {
     $sql = "DELETE FROM `fcms_documents` \n                WHERE `id` = ?";
     if (!$this->fcmsDatabase->delete($sql, $_POST['id'])) {
         $this->displayHeader();
         $this->fcmsError->displayError();
         $this->displayFooter();
         return;
     }
     $uploadsPath = getUploadsAbsolutePath();
     if (!unlink($uploadsPath . 'documents/' . basename($_POST['name']))) {
         $this->displayHeader();
         echo '<p class="error-alert">' . T_('Document could not be deleted from the server.') . '</p>';
         $this->displayFooter();
         return;
     }
     header("Location: documents.php");
 }
Example #6
0
/**
 * displayImages 
 * 
 * @return void
 */
function displayImages()
{
    global $fcmsUser;
    displayHeader();
    if (isset($_SESSION['delete_ok'])) {
        unset($_SESSION['delete_ok']);
        echo '<p class="ok-alert">' . T_('Image was Deleted Successfully') . '</p>';
    }
    echo '
    <h2>' . T_('Upload Image') . '</h2>
    <form enctype="multipart/form-data" action="upimages.php" method="post">
        <p><input type="file" name="upfile" id="upfile" size="30" title="' . T_('Choose the image you want to upload.') . '"/></p>
        <div><input type="submit" name="upload" id="upload" value="' . T_('Upload Image') . '"/></div>
    </form>
    <p>&nbsp;</p>
    <h2>' . T_('Uploaded Images') . '</h2>
    <table>';
    $uploadsPath = getUploadsAbsolutePath();
    $img_dir = opendir($uploadsPath . 'upimages');
    while ($file = readdir($img_dir)) {
        if ($file !== 'index.htm') {
            $images_in_dir[] = $file;
        }
    }
    natcasesort($images_in_dir);
    reset($images_in_dir);
    $i = 0;
    $total_size = 0;
    foreach ($images_in_dir as $file) {
        // Skip directories that start with a period
        if ($file[0] === '.') {
            continue;
        }
        $img_name_arr = explode(".", $file);
        $img_type = end($img_name_arr);
        $this_size = filesize($uploadsPath . 'upimages/' . $file);
        $total_size += $this_size;
        $img_info = getimagesize($uploadsPath . 'upimages/' . $file);
        $win_w = $img_info[0] + 50;
        $win_h = $img_info[1] + 50;
        $path = 'uploads/upimages/';
        if (defined('UPLOADS')) {
            $path = 'file.php?u=';
        }
        $i++;
        echo '
        <tr';
        if ($i % 2 != 0) {
            echo 'class="alt"';
        }
        echo '>
            <td class="v">
                <button class="viewbtn" onclick="window.open(\'' . URL_PREFIX . $path . basename($file) . '\',\'file\',
                \'width=' . $win_w . ',height=' . $win_h . ',resizable=no,location=no,menubar=no,status=no\'); return false;"/>
            </td>
            <td class="file">
                <a href="#" onclick="insertUpImage(\'[IMG=' . $path . basename($file) . ']\')" 
                    title="' . T_('Click to insert image into message.') . '">' . $file . '</a>
            </td>
            <td>';
        if ($fcmsUser->access < 2) {
            echo '
                <form method="post" action="upimages.php">
                    <div>
                        <input type="hidden" name="img" value="' . cleanOutput($file) . '"/>
                        <input type="submit" name="delimg" value="' . T_('Delete') . '" class="delbtn" title="' . T_('Delete this Image') . '" 
                            onclick="javascript:return confirm(\'' . T_('Are you sure you want to DELETE this image?') . '\');"/>
                    </div>
                </form>';
        }
        echo '
            </td>
            <td class="n">' . $img_info[0] . 'x' . $img_info[1] . '</td>
            <td class="n">' . formatSize($this_size) . '</td>
        </tr>';
    }
    echo '
        <tr>
            <td></td>
            <td></td>
            <td></td>
            <td class="n">' . T_('Total Size') . '</td>
            <td class="n">' . formatSize($total_size) . '</td>
        </tr>
    </table>';
    displayFooter();
}
Example #7
0
 /**
  * uploadDocument 
  * 
  * @param  file   $file 
  * @param  string $filename 
  * @return void
  */
 function uploadDocument($file, $filename)
 {
     $valid_docs = array('application/octet-stream' => 'doc', 'application/msword' => 'doc', 'application/msword' => 'dot', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' => 'docx', 'application/vnd.openxmlformats-officedocument.wordprocessingml.template' => 'dotx', 'application/excel' => 'xls', 'application/x-excel' => 'xls', 'application/x-msexcel' => 'xls', 'application/vnd.ms-excel' => 'xls', 'application/vnd.ms-excel' => 'xlt', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' => 'xlsx', 'application/vnd.openxmlformats-officedocument.spreadsheetml.template' => 'xltx', 'application/mspowerpoint' => 'ppt', 'application/powerpoint' => 'ppt', 'application/x-mspowerpoint' => 'ppt', 'application/vnd.ms-powerpoint' => 'ppt', 'application/vnd.ms-powerpoint' => 'pot', 'application/vnd.openxmlformats-officedocument.presentationml.presentation' => 'pptx', 'application/vnd.openxmlformats-officedocument.presentationml.template' => 'potx', 'application/msaccess' => 'accdb', 'application/vnd.oasis.opendocument.presentation' => 'odp', 'application/vnd.oasis.opendocument.spreadsheet' => 'ods', 'application/vnd.oasis.opendocument.text' => 'odt', 'text/plain' => 'txt', 'text/css' => 'css', 'application/rtf' => 'rtf', 'application/x-rtf' => 'rtf', 'text/richtext' => 'rtf', 'application/pdf' => 'pdf', 'application/x-compressed' => 'zip', 'application/x-zip-compressed' => 'zip', 'application/x-zip' => 'zip', 'application/zip' => 'zip', 'multipart/x-zip' => 'zip');
     $filetmpname = $file['tmp_name'];
     $filetype = $file['type'];
     $error = $file['error'];
     $ext = explode(".", strtolower($file['name']));
     $ext = end($ext);
     // Check max file size
     if ($error == 1) {
         $this->fcmsError->add(array('message' => T_('Document too large.'), 'details' => '<p>' . sprintf(T_('Document %s exceeds the maximum file size allowed by your PHP settings.'), $filename) . '</p>'));
         return false;
     }
     // Check allowable file type
     if (!array_key_exists($filetype, $valid_docs) || !in_array($ext, $valid_docs)) {
         $this->fcmsError->add(array('message' => T_('Invalid Document'), 'details' => '<p>' . $filename . ' &nbsp;<small><i>(' . $filetype . ')</i></small></p><p>' . T_('Documents must be of type (.doc, .txt, .xsl, .zip, .rtf, .ppt, .pdf).') . '</p>'));
         return false;
     }
     $filename = basename($filename);
     // just the filename, no paths
     $uploadsPath = getUploadsAbsolutePath();
     // Check if a file with that name exists already
     if (file_exists($uploadsPath . 'documents/' . $filename)) {
         $this->fcmsError->add(array('message' => sprintf(T_('Document %s already exists!  Please change the filename and try again.'), $filename), 'file' => __FILE__, 'line' => __LINE__));
         return false;
     }
     // Upload the file
     copy($filetmpname, $uploadsPath . 'documents/' . $filename);
     return true;
 }