Example #1
0
function forum_edit_replay($id, $bid, $tid)
{
    global $db;
    $thread = $db->fetch_assoc('SELECT `threadID`, `bID`, `threadname`, a.boardparentID, ' . DB_PRE . 'ecp_forum_threads.closed,userID, comment, attachs,postname, adatum, 
									    a.editcom,a.editmocom,a.rightsread, a.commentsperpost, a.moneyperpost, a.boardparentID, 
									    a.name, a.attachments, a.attachmaxsize, a.postcom, a.attachfiles, b.rightsread as parentRead 
									    FROM ' . DB_PRE . 'ecp_forum_threads 
									    LEFT JOIN ' . DB_PRE . 'ecp_forum_boards AS a ON (bID = a.boardID) 
									    LEFT JOIN ' . DB_PRE . 'ecp_forum_boards AS b ON (b.boardID = a.boardparentID) 
									    LEFT JOIN ' . DB_PRE . 'ecp_forum_comments ON (comID = ' . $id . ')
									    WHERE threadID = ' . $tid . ' AND bID = ' . $bid);
    if (@$_SESSION['userID'] and find_access($thread['rightsread']) and find_access($thread['parentRead']) and (find_access($thread['editcom']) and $_SESSION['userID'] == $thread['userID'] or find_access($thread['editmocom'])) and $db->errorNum() == 0) {
        if (isset($_POST['comment'])) {
            if ($_POST['comment'] == '' or isset($_POST['username']) and $_POST['username'] == '' or isset($_POST['title']) and $_POST['title'] == '') {
                table(ERROR, NOT_NEED_ALL_INPUTS);
                $tpl = new smarty();
                $tpl->assign('func', 'edit');
                $tpl->assign('func2', '&comID=' . $id);
                $tpl->assign('comment', $_POST['comment']);
                if ($db->result(DB_PRE . 'ecp_forum_comments', 'COUNT(comID)', 'tID = ' . $tid . ' AND adatum < ' . $thread['adatum'] . ' ORDER BY adatum ASC') == 0) {
                    $tpl->assign('title', $thread['threadname']);
                }
                if ($thread['userID'] == 0) {
                    $tpl->assign('username', $thread['postname']);
                }
                ob_start();
                if ($thread['attachments'] and $thread['attachmaxsize']) {
                    $attachs = $db->result(DB_PRE . 'ecp_forum_attachments', 'COUNT(attachID)', 'mID = ' . $id . ' AND tID = ' . $tid);
                    if ($thread['attachments'] > $attachs) {
                        $rand = get_random_string(16, 2);
                        $tpl->assign('attach', find_access($thread['attachfiles']));
                        $tpl->assign('maxsize', $thread['attachmaxsize']);
                        $tpl->assign('rand', $rand);
                        $tpl->assign('sid', session_name() . '=' . session_id());
                        $tpl->assign('maxuploads', $thread['attachments'] - $attachs);
                        $tpl->assign('uploadinfo', str_replace(array('{anzahl}', '{max}'), array($thread['attachments'] - $attachs, goodsize($thread['attachmaxsize'])), FORUM_ATTACH_INFO));
                        $_SESSION['forum']['attach'][$bid] = $rand;
                    }
                }
                $tpl->assign('quote', true);
                $tpl->display(DESIGN . '/tpl/forum/comments_add_edit' . ((UPLOAD_METHOD == 'old' and $thread['attachments'] and $thread['attachmaxsize']) ? '_old' : '') . '.html');
                $content = ob_get_contents();
                ob_end_clean();
                main_content(FORUM_POST_EDIT, $content, '', 1);
            } else {
                if ($db->query(sprintf('UPDATE ' . DB_PRE . 'ecp_forum_comments SET postname = \'%s\', comment = \'%s\', edits =edits +1, editdatum = %d, edituserID = %d WHERE comID = %d', strsave(htmlspecialchars(@$_POST['username'])), strsave(comment_save($_POST['comment'])), time(), @(int) $_SESSION['userID'], $id))) {
                    if (find_access($thread['attachfiles'])) {
                        if (UPLOAD_METHOD == 'old') {
                            $maxattach = $thread['attachments'] - $db->result(DB_PRE . 'ecp_forum_attachments', 'COUNT(attachID)', 'bID = ' . $bid . ' AND mID = ' . $id);
                            foreach ($_FILES as $key => $value) {
                                if ($_FILES[$key] == '' or $maxattach <= 0 or $_FILES[$key]['size'] > $thread['attachmaxsize']) {
                                    continue;
                                }
                                $mine = getMimeType($_FILES[$key]['tmp_name'], $_FILES[$key]['name']);
                                if ($mine == 'application/zip' or $mine == 'application/x-rar-compressed' or $mine == 'image/bmp' or $mine == 'image/gif' or $mine == 'image/jpeg' or $mine == 'image/png' or $mine == 'application/pdf' or $mine == 'text/plain' or $mine == 'text/css' or $mine == 'text/html') {
                                    $sha1 = sha1_file($_FILES[$key]['tmp_name']);
                                    if ($db->query(sprintf('INSERT INTO ' . DB_PRE . 'ecp_forum_attachments (`bID`, `userID`, `name`, `size`, `strname`, uploadzeit, IP, tID, mID) VALUES (%d, %d, \'%s\', %d, \'%s\', %d, \'%s\', %d, %d)', $bid, @(int) $_SESSION['userID'], strsave($_FILES[$key]['name']), (int) $_FILES[$key]['size'], $sha1, time(), $_SERVER['REMOTE_ADDR'], $tid, $id))) {
                                        move_uploaded_file($_FILES[$key]['tmp_name'], 'uploads/forum/' . $db->last_id() . '_' . $sha1);
                                        umask(0);
                                        chmod('uploads/forum/' . $db->last_id() . '_' . $sha1, CHMOD);
                                        $db->query('UPDATE ' . DB_PRE . 'ecp_forum_threads SET anhaenge = 1 WHERE threadID = ' . $tid);
                                        $db->query('UPDATE ' . DB_PRE . 'ecp_forum_comments SET attachs = 1 WHERE comID = ' . $id);
                                    }
                                    $maxattach--;
                                }
                            }
                        } else {
                            $db->query(sprintf('UPDATE ' . DB_PRE . 'ecp_forum_attachments SET `tID` = %d, `mID` = %d WHERE validation = \'%s\' AND bID = %d', $id, $comid, strsave($_GET['rand']), $bid));
                            if ($db->affekt_rows()) {
                                $db->query('UPDATE ' . DB_PRE . 'ecp_forum_threads SET anhaenge = 1 WHERE threadID = ' . $id);
                                $db->query('UPDATE ' . DB_PRE . 'ecp_forum_comments SET attachs = 1 WHERE comID = ' . $comid);
                            }
                        }
                    }
                    if ($db->result(DB_PRE . 'ecp_forum_comments', 'COUNT(comID)', 'tID = ' . $tid . ' AND adatum < ' . $thread['adatum'] . ' ORDER BY adatum ASC') == 0) {
                        $db->query('UPDATE ' . DB_PRE . 'ecp_forum_threads SET threadname = \'' . strsave(htmlspecialchars($_POST['title'])) . '\', vonname = \'' . strsave(htmlspecialchars(@$_POST['username'])) . '\' WHERE threadID = ' . $tid);
                    }
                    $last = $db->fetch_assoc('SELECT userID,postname,adatum, tID FROM ' . DB_PRE . 'ecp_forum_comments WHERE boardID = ' . $bid . ' ORDER BY adatum DESC LIMIT 1');
                    $db->query('UPDATE ' . DB_PRE . 'ecp_forum_boards SET `lastpostuserID` =  ' . (int) $last['userID'] . ', `lastpostuser` = \'' . $last['postname'] . '\', `lastpost` = ' . (int) $last['adatum'] . ', lastthreadID = ' . (int) $last['tID'] . ' WHERE (boardID = ' . $bid . ' OR boardID = ' . $thread['boardparentID'] . ')');
                    $last = $db->fetch_assoc('SELECT userID,postname,adatum FROM ' . DB_PRE . 'ecp_forum_comments WHERE tID = ' . $tid . ' ORDER BY adatum DESC LIMIT 1');
                    $db->query('UPDATE ' . DB_PRE . 'ecp_forum_threads SET `lastuserID` =  ' . $last['userID'] . ', `lastusername` = \'' . $last['postname'] . '\', `lastreplay` = ' . $last['adatum'] . ' WHERE threadID = ' . $tid);
                    unset($_SESSION['forum']['attach'][$bid]);
                    $anzahl = $db->result(DB_PRE . 'ecp_forum_comments', 'COUNT(comID)', 'tID = ' . $tid . ' AND boardID =' . $bid . ' AND adatum < ' . $thread['adatum']);
                    header1('?section=forum&action=thread&boardID=' . $bid . '&threadID=' . $tid . '&page=' . (ceil(($anzahl - 1) / LIMIT_FORUM_COMMENTS) + 1) . '#com_' . $id);
                }
            }
        } else {
            $tpl = new smarty();
            $tpl->assign('comment', htmlspecialchars($thread['comment']));
            $tpl->assign('func', 'edit');
            $tpl->assign('func2', '&comID=' . $id);
            if ($db->result(DB_PRE . 'ecp_forum_comments', 'COUNT(comID)', 'tID = ' . $tid . ' AND adatum < ' . $thread['adatum'] . ' ORDER BY adatum ASC') == 0) {
                $tpl->assign('title', $thread['threadname']);
            }
            if ($thread['userID'] == 0) {
                $tpl->assign('username', $thread['postname']);
            }
            ob_start();
            if ($thread['attachments'] and $thread['attachmaxsize']) {
                $attachs = $db->result(DB_PRE . 'ecp_forum_attachments', 'COUNT(attachID)', 'mID = ' . $id . ' AND tID = ' . $tid);
                if ($thread['attachments'] > $attachs) {
                    $rand = get_random_string(16, 2);
                    $tpl->assign('attach', find_access($thread['attachfiles']));
                    $tpl->assign('maxsize', $thread['attachmaxsize']);
                    $tpl->assign('rand', $rand);
                    $tpl->assign('sid', session_name() . '=' . session_id());
                    $tpl->assign('maxuploads', $thread['attachments'] - $attachs);
                    $tpl->assign('uploadinfo', str_replace(array('{anzahl}', '{max}'), array($thread['attachments'] - $attachs, goodsize($thread['attachmaxsize'])), FORUM_ATTACH_INFO));
                    $_SESSION['forum']['attach'][$bid] = $rand;
                }
            }
            $tpl->assign('quote', true);
            $tpl->display(DESIGN . '/tpl/forum/comments_add_edit' . ((UPLOAD_METHOD == 'old' and $thread['attachments'] and $thread['attachmaxsize']) ? '_old' : '') . '.html');
            $content = ob_get_contents();
            ob_end_clean();
            main_content(FORUM_POST_EDIT, $content, '', 1);
        }
    } else {
        table(ERROR, ACCESS_DENIED);
    }
}
	<meta name="author" content="Brian Sandall" /> 
</head>
<?php 
$errors = array();
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $file = trim(filter_input(INPUT_POST, 'file'));
    if (!empty($file) && is_string($file)) {
        if (strpos($file, '..') !== false) {
            $errors['file'] = '* Invalid file path';
        } else {
            $file = ltrim(rtrim($file, '\\/'), '\\/');
            $filename = PATH . $file;
            if (!is_file($filename)) {
                $errors['file'] = '* Invalid file path or file name';
            } elseif (getMimeType($filename) !== 'text/plain') {
                $errors['file'] = '* Invalid file type: ' . getMimeType($filename);
            }
        }
    } else {
        $errors['file'] = '* Required field';
    }
    $required = array('product_code' => true, 'list_price' => true, 'sale_price' => true);
    $header_labels = filter_input(INPUT_POST, 'header_labels', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY);
    if (!is_array($header_labels)) {
        $errors['header_labels']['missing'] = '* Please enter valid header labels';
    } else {
        foreach ($header_labels as $k => $v) {
            if (empty($v) && !empty($required[$k])) {
                $errors['header_labels'][$k] = '* Required field';
            } elseif (!preg_match('/^[a-z0-9-_\\040]+$/i', $v)) {
                $errors['header_labels'][$k] = '* Only letters, digits, spaces, hyphens, and underscores are allowed';
Example #3
0
 /**
  * return the content of the pictures
  * @param Picture[] $pictures the list of the pictures
  * @return Picture[]
  */
 protected function getPicturesData(array $pictures)
 {
     $this->api->getPool(array_map(function (Picture $picture) {
         return new Request('GET', $picture->url);
     }, $pictures), ['fulfilled' => function (Response $response, $index) use($pictures) {
         $pictures[$index]->content = $response->getBody()->getContents();
         $pictures[$index]->mimetype = getMimeType($pictures[$index]->content);
     }])->wait();
     return $pictures;
 }
Example #4
0
}
# In order to not processed l10 for config.xml
# TODO And for the locales folders ?
# Get le localized resource content
$urlsToLocalizedResource = getUrlsToBeParsed($choosedLangages, $requestedURI);
$urlsToPaths = urlsToFiles($urlsToLocalizedResource, '/.*widgets/', dirname(__FILE__));
$resourceContent = getFirstFileContentFromTab($urlsToPaths);
# Debuging
//var_dump($choosedLangages);
//var_dump($requestedURI);
//var_dump($urlsToLocalizedResource);
//var_dump($urlsToPaths);
//var_dump($resourceContent);
# Send the content to the client
//header('Cache-Control: no-store, proxy-revalidate, no-cache, must-revalidate, post-check=0, pre-check=0, max-age=0, s-maxage=0');
header('Content-Type: ' . getMimeType($requestedURI));
# To avoid bug
if ($resourceContent === FALSE) {
    echo 'l10n cannot resolve : ' . $requestedURI;
} else {
    echo $resourceContent;
}
//--------------------- Funtions used within the process ----------------------------------
/**
 * this function return the content of the first existing file in am array of file
 */
function getFirstFileContentFromTab($files)
{
    $n = count($files);
    for ($i = 0; $i < $n; $i++) {
        $content = @file_get_contents($files[$i]);
Example #5
0
                                 if ($size[0] > GALLERY_THUMB_SIZE) {
                                     resize_picture('images/gallery/' . $gallery['folder'] . '/' . $id . '_' . $sha1 . '.jpg', GALLERY_THUMB_SIZE, 'images/gallery/' . $gallery['folder'] . '/thumbs/' . $id . '_' . $sha1 . '.jpg', 100, 0);
                                 } else {
                                     copy('images/gallery/' . $gallery['folder'] . '/' . $id . '_' . $sha1 . '.jpg', 'images/gallery/' . $gallery['folder'] . '/thumbs/' . $id . '_' . $sha1 . '.jpg');
                                     umask(0);
                                     chmod('images/gallery/' . $gallery['folder'] . '/thumbs/' . $id . '_' . $sha1 . '.jpg', CHMOD);
                                 }
                                 if ($size[0] > GALLERY_PIC_SIZE) {
                                     resize_picture('images/gallery/' . $gallery['folder'] . '/' . $id . '_' . $sha1 . '.jpg', GALLERY_PIC_SIZE, 'images/gallery/' . $gallery['folder'] . '/' . $id . '_' . $sha1 . '.jpg', 100);
                                 }
                             } else {
                                 @($error .= 'Datei konnte nicht verschoben werden.(' . $_FILES[$key]['name'] . ')<br />');
                             }
                         }
                     } else {
                         @($error .= WRONG_FILE_TYPE . ' (' . $_FILES[$key]['name'] . ' : ' . getMimeType($_FILES[$key]['tmp_name'], $_FILES[$key]['name']) . ')<br />');
                     }
                 }
             } else {
                 $error = FILE_NOT_FOUND;
             }
         } else {
             $error = FILE_EXIST;
         }
     } else {
         $error = 'Es wurde keine Datei hochgeladen.';
     }
 } else {
     $error = NO_ADMIN_RIGHTS;
 }
 if (UPLOAD_METHOD == 'Flash') {
function phpftp_view($ftp, $tempdir, $dir, $file)
{
    $tmpfile = tempnam('/tmp', 'egwftp');
    ftp_chdir($ftp, $dir);
    $remotefile = $dir . '/' . $file;
    if (!ftp_get($ftp, $tmpfile, $remotefile, FTP_BINARY)) {
        echo 'tmpfile="' . $tmpfile . '",file="' . $remotefile . '"<br>' . "\n";
        macro_get_Link('newlogin', 'Start over?');
        $retval = 0;
    } else {
        $content_type = getMimeType($remotefile);
        header('Content-Type: ' . $content_type);
        readfile($tmpfile);
        $retval = 1;
    }
    @unlink($tmpfile);
    return $retval;
}
Example #7
0
File: index.php Project: kawf/kawf
function getMimeType($filename)
{
    $realpath = realpath($filename);
    if ($realpath && function_exists('finfo_file') && function_exists('finfo_open') && defined('FILEINFO_MIME_TYPE')) {
        // Use the Fileinfo PECL extension (PHP 5.3+)
        return finfo_file(finfo_open(FILEINFO_MIME_TYPE), $realpath);
    }
    if (function_exists('mime_content_type')) {
        // Deprecated in PHP 5.3
        return mime_content_type($realpath);
    }
    return false;
}
/* emulate RewriteRule  ^/(pics/.*|css/.*|scripts/.*|robots.txt|favicon.ico|apple-touch-icon.png)$ /$1 */
if (preg_match('@^/(pics/.*|robots.txt|favicon.ico|apple-touch-icon.png)$@', $path, $matches)) {
    header('Content-Type: ' . getMimeType($matches[1]));
    require $matches[1];
    return;
}
if (preg_match('@^/(css/.*)$@', $path, $matches)) {
    $file = $matches[1];
    header('Content-Type: text/css');
    require $file;
    return;
}
if (preg_match('@^/(scripts/.*)$@', $path, $matches)) {
    $file = $matches[1];
    header('Content-Type: application/javascript');
    require $file;
    return;
}
Example #8
0
             }
         } else {
             die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "Failed to open input stream."}, "id" : "id"}');
         }
         fclose($in);
         fclose($out);
     } else {
         die('{"jsonrpc" : "2.0", "error" : {"code": 102, "message": "Failed to open output stream."}, "id" : "id"}');
     }
 }
 // only generate thumbs/previews if this is the last chunk
 if ($chunk == $chunks - 1) {
     // temp variable for uploaded file (and path)
     $uploadedFile = $targetDir . DIRECTORY_SEPARATOR . $fileName;
     // get MIME type
     $mime = getMimeType($uploadedFile);
     // get extension
     $ext = pathinfo($uploadedFile, PATHINFO_EXTENSION);
     // validate MIME type and extension
     if (!Upload::isAllowedMime($mime) || !Upload::isAllowedExtension($ext)) {
         // delete the file we just uploaded and send us back
         chown($uploadedFile, 666);
         unlink($uploadedFile);
         die('{"jsonrpc" : "2.0", "error" : {"code": 104, "message": "That file type is not allowed."}, "id" : "' . $fileName . '"}');
     }
     // make large thumb
     // calculate resized width and height
     list($orig_width, $orig_height) = @getimagesize($uploadedFile);
     $scale = min(User::PICTURE_LARGE_MAX_WIDTH / $orig_width, User::PICTURE_LARGE_MAX_HEIGHT / $orig_height);
     if ($scale > 1) {
         $scale = 1;
Example #9
0
/**
 * @param string $mime_type
 * @return bool|string
 */
function getExtension($mime_type)
{
    if (empty($mime_type)) {
        return false;
    }
    $extensions = getMimeType(null, null, true);
    $ext = array_search($mime_type, $extensions);
    return $ext ? $ext : false;
}
 function uploadFile()
 {
     $cachedfolder = $this->cache->isCached($this->_requestedEntry);
     if ($cachedfolder === false) {
         $cachedfolder = $this->getEntry($this->_requestedEntry);
         if ($cachedfolder === false) {
             return new WP_Error('broke', __("Root folder not found ", 'useyourdrive'));
             die;
         }
     }
     /* Check if user is allowed to upload to this dir */
     if (!$cachedfolder->isInFolder($this->_rootFolder)) {
         return new WP_Error('broke', __("You are not authorized to upload files to this directory", 'useyourdrive'));
         die;
     }
     /* Upload File to server */
     require 'jquery-file-upload/server/UploadHandler.php';
     $accept_file_types = '/.(' . $this->options['upload_ext'] . ')$/i';
     $max_file_size = $this->options['maxfilesize'];
     $uploadir = wp_upload_dir();
     $options = array('upload_dir' => $uploadir['path'] . '/', 'upload_url' => $uploadir['url'] . '/', 'access_control_allow_methods' => array('POST', 'PUT'), 'accept_file_types' => $accept_file_types, 'inline_file_types' => '/\\.____$/i', 'orient_image' => false, 'image_versions' => array(), 'max_file_size' => $max_file_size, 'print_response' => false);
     if ($this->options['demo'] === '1') {
         $options['accept_file_types'] = '/\\.____$/i';
     }
     $error_messages = array(1 => __('The uploaded file exceeds the upload_max_filesize directive in php.ini', 'useyourdrive'), 2 => __('The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form', 'useyourdrive'), 3 => __('The uploaded file was only partially uploaded', 'useyourdrive'), 4 => __('No file was uploaded', 'useyourdrive'), 6 => __('Missing a temporary folder', 'useyourdrive'), 7 => __('Failed to write file to disk', 'useyourdrive'), 8 => __('A PHP extension stopped the file upload', 'useyourdrive'), 'post_max_size' => __('The uploaded file exceeds the post_max_size directive in php.ini', 'useyourdrive'), 'max_file_size' => __('File is too big', 'useyourdrive'), 'min_file_size' => __('File is too small', 'useyourdrive'), 'accept_file_types' => __('Filetype not allowed', 'useyourdrive'), 'max_number_of_files' => __('Maximum number of files exceeded', 'useyourdrive'), 'max_width' => __('Image exceeds maximum width', 'useyourdrive'), 'min_width' => __('Image requires a minimum width', 'useyourdrive'), 'max_height' => __('Image exceeds maximum height', 'useyourdrive'), 'min_height' => __('Image requires a minimum height', 'useyourdrive'));
     $this->upload_handler = new UploadHandler($options, false, $error_messages);
     $response = @$this->upload_handler->post(false);
     /* Upload files to Google Drive */
     foreach ($response['files'] as &$file) {
         /* Check user permission */
         $userrole = $cachedfolder->getItem()->getUserPermission()->getRole();
         if (in_array($userrole, array('reader', 'commenter'))) {
             $file->error = __("You are not authorized to upload files to this directory", 'useyourdrive');
         }
         if (!isset($file->error)) {
             /* Write file */
             $filePath = $file->tmp_path;
             $chunkSizeBytes = 1 * 1024 * 1024;
             /* Update Mime-type if needed (for IE8 and lower?) */
             include_once 'mime-types/mime-types.php';
             $fileExtension = pathinfo($file->name, PATHINFO_EXTENSION);
             $file->type = getMimeType($fileExtension);
             try {
                 /* Create new Google File */
                 $googledrive_file = new Google_Service_Drive_DriveFile();
                 $googledrive_file->setTitle($file->name);
                 $googledrive_file->setMimeType($file->type);
                 /* Add Parent to Google File */
                 if ($this->_lastFolder != null) {
                     $parent = new Google_Service_Drive_ParentReference();
                     $parent->setId($this->_lastFolder);
                     $googledrive_file->setParents(array($parent));
                 }
                 /* Call the API with the media upload, defer so it doesn't immediately return. */
                 $this->client->setDefer(true);
                 $convert = $this->options['convert'] === '1' ? true : false;
                 $request = $this->googleDriveService->files->insert($googledrive_file, array('convert' => $convert));
                 $request->disableGzip();
                 /* Create a media file upload to represent our upload process. */
                 $media = new Google_Http_MediaFileUpload($this->client, $request, $file->type, null, true, $chunkSizeBytes);
                 $media->setFileSize(filesize($filePath));
                 /* Start partialy upload 
                    Upload the various chunks. $status will be false until the process is
                    complete. */
                 $status = false;
                 $handle = fopen($filePath, "rb");
                 while (!$status && !feof($handle)) {
                     set_time_limit(60);
                     $chunk = fread($handle, $chunkSizeBytes);
                     $uploadStatus = $media->nextChunk($chunk);
                 }
                 fclose($handle);
             } catch (Exception $ex) {
                 $file->error = __('Not uploaded to Google Drive', 'useyourdrive') . ': ' . $ex->getMessage();
             }
             $this->client->setDefer(false);
             if (!empty($uploadStatus)) {
                 /* check if uploaded file has size */
                 $newentry = $this->googleDriveService->files->get($uploadStatus['id'], array("userIp" => $this->userip));
                 if ($newentry->getFileSize() === 0 && strpos($newentry->getMimeType(), 'google-apps') === false) {
                     $deletedentry = $this->googleDriveService->files->delete($newentry->getId(), array("userIp" => $this->userip));
                     $file->error = __('Not succesfully uploaded to Google Drive', 'useyourdrive');
                 } else {
                     /* Add new file to our Cache */
                     $cachedentry = $this->cache->addToCache($newentry);
                     $file->completepath = $cachedentry->getPath($this->_rootFolder);
                     $file->fileid = $newentry->getId();
                     $file->filesize = UseyourDrive_bytesToSize1024($file->size);
                     $file->link = urlencode($newentry->getAlternateLink());
                 }
             }
         } else {
             if ($this->options['debug'] === '1') {
                 $file->error = __('Uploading failed', 'useyourdrive') . ': ' . $file->error;
             } else {
                 $file->error = __('Uploading failed', 'useyourdrive');
             }
         }
     }
     /* Send email if needed */
     if ($this->options['notificationupload'] === '1') {
         $this->sendNotificationEmail('upload', $response['files']);
     }
     /* Create response */
     $this->upload_handler->generate_response($response);
     die;
 }
Example #11
0
/**
 * Encode the contents of a file for emailing, including headers
 * 
 * $file can be an array, in which case it expects these members:
 *   'filename'        - the filename of the file
 *   'contents'        - the raw binary contents of the file as a string
 *  and can optionally include these members:
 *   'mimetype'        - the mimetype of the file (calculated from filename if missing)
 *   'contentLocation' - the 'Content-Location' header value for the file
 *   
 * $file can also be a string, in which case it is assumed to be the filename
 * 
 * h5. contentLocation
 * 
 * Content Location is one of the two methods allowed for embedding images into an html email. It's also the simplest, and best supported
 * 
 * Assume we have an email with this in the body:
 * 
 *   <img src="http://example.com/image.gif" />
 * 
 * To display the image, an email viewer would have to download the image from the web every time it is displayed. Due to privacy issues, most
 * viewers will not display any images unless the user clicks 'Show images in this email'. Not optimal.
 * 
 * However, we can also include a copy of this image as an attached file in the email. By giving it a contentLocation of "http://example.com/image.gif"
 * most email viewers will use this attached copy instead of downloading it. Better, most viewers will show it without a 'Show images in this email'
 * conformation.
 * 
 * Here is an example of passing this information through Email.php:
 * 
 *   $email = new Email();
 *   $email->attachments[] = array(
 *     'filename' => BASE_PATH . "/themes/mytheme/images/header.gif",
 *     'contents' => file_get_contents(BASE_PATH . "/themes/mytheme/images/header.gif"),
 *     'mimetype' => 'image/gif',
 *     'contentLocation' => Director::absoluteBaseURL() . "/themes/mytheme/images/header.gif"
 *   );
 * 
 */
function encodeFileForEmail($file, $destFileName = false, $disposition = NULL, $extraHeaders = "")
{
    if (!$file) {
        user_error("encodeFileForEmail: not passed a filename and/or data", E_USER_WARNING);
        return;
    }
    if (is_string($file)) {
        $file = array('filename' => $file);
        $fh = fopen($file['filename'], "rb");
        if ($fh) {
            while (!feof($fh)) {
                $file['contents'] .= fread($fh, 10000);
            }
            fclose($fh);
        }
    }
    // Build headers, including content type
    if (!$destFileName) {
        $base = basename($file['filename']);
    } else {
        $base = $destFileName;
    }
    $mimeType = $file['mimetype'] ? $file['mimetype'] : getMimeType($file['filename']);
    if (!$mimeType) {
        $mimeType = "application/unknown";
    }
    if (empty($disposition)) {
        $disposition = isset($file['contentLocation']) ? 'inline' : 'attachment';
    }
    // Encode for emailing
    if (substr($file['mimetype'], 0, 4) != 'text') {
        $encoding = "base64";
        $file['contents'] = chunk_split(base64_encode($file['contents']));
    } else {
        // This mime type is needed, otherwise some clients will show it as an inline attachment
        $mimeType = 'application/octet-stream';
        $encoding = "quoted-printable";
        $file['contents'] = QuotedPrintable_encode($file['contents']);
    }
    $headers = "Content-type: {$mimeType};\n\tname=\"{$base}\"\n" . "Content-Transfer-Encoding: {$encoding}\n" . "Content-Disposition: {$disposition};\n\tfilename=\"{$base}\"\n";
    if (isset($file['contentLocation'])) {
        $headers .= 'Content-Location: ' . $file['contentLocation'] . "\n";
    }
    $headers .= $extraHeaders . "\n";
    // Return completed packet
    return $headers . $file['contents'];
}
Example #12
0
        return "image/jpeg";
    } else {
        if ($raw_file[1] == "png") {
            return "image/png";
        } else {
            header("HTTP/1.1 500 What Is This");
            exit;
        }
    }
}
function drawBlankTile()
{
    $image = imagecreate(256, 256);
    $watercolor = imagecolorallocate($image, 29, 71, 95);
    #1D475F used by frontend map.js
    imagefill($image, 0, 0, $watercolor);
    header("Content-Type: image/png");
    imagepng($image);
    imagedestroy($image);
}
$config =& get_config();
$map_tile = getRequestedTileName();
$map_dir = !empty($config['map_path']) ? $config['map_path'] : BASEPATH . 'map/';
$filename = $map_dir . "/{$map_tile}";
if (file_exists($filename)) {
    $mime_type = getMimeType($map_tile);
    header("Content-Type: {$mime_type}");
    readfile($filename);
} else {
    drawBlankTile();
}
Example #13
0
 public static function saveToDatabase($originalName = null, $storedName = null, $itemType = null, $itemID = null, $projectID = null)
 {
     // all but projectID required
     if ($originalName == null || $storedName == null || $itemType == null || $itemID == null) {
         return null;
     }
     // get extension
     $ext = pathinfo($originalName, PATHINFO_EXTENSION);
     $storedName .= '.' . $ext;
     // temp variable for absolute path
     $absPath = UPLOAD_PATH . '/' . $storedName;
     // get file size
     $size = filesize($absPath);
     // get mime type
     $mime = getMimeType($absPath);
     // get height and width (if image)
     $imgSize = getimagesize($absPath);
     if ($imgSize) {
         $height = $imgSize[1];
         $width = $imgSize[0];
     } else {
         $height = null;
         $width = null;
     }
     // store in db
     $upload = new Upload(array('creator_id' => Session::getUserID(), 'original_name' => $originalName, 'stored_name' => $storedName, 'mime' => $mime, 'size' => $size, 'height' => $height, 'width' => $width, 'item_type' => $itemType, 'item_id' => $itemID, 'project_id' => $projectID));
     $upload->save();
     return $upload->getID();
 }
Example #14
0
        $fullLink = $href;
    } else {
        if (substr($href, 0, 1) === "/") {
            $path = substr_replace($_POST["url"], "", $_POST["url"] . length - 1, 1);
            $fullLink = $path . $href;
        }
    }
    // Attempt to visit page
    if ($file = @fopen($fullLink, "r")) {
        $page = "Available!";
        fclose($file);
    } else {
        $page = "Unknown!";
    }
    // Formatting
    echo "<tr>\n    <td>" . $link->nodeValue . "</td>\n    <td>" . $fullLink . "</td>;\n    <td>" . getMimeType(pathinfo($href, PATHINFO_EXTENSION)) . "</td>\n    <td>" . $page . "</td>\n    </tr>";
    $linkCount++;
}
echo "</table>";
if ($linkCount > 0) {
    echo $linkCount, " Links found!";
} else {
    echo "No links found! <br> Empty/Non-Existent page!";
}
function getMimeType($file)
{
    // MIME types array - Courtesy of Phill Pafford from StackOverflow
    $mimeTypes = array("323" => "text/h323", "acx" => "application/internet-property-stream", "ai" => "application/postscript", "aif" => "audio/x-aiff", "aifc" => "audio/x-aiff", "aiff" => "audio/x-aiff", "asf" => "video/x-ms-asf", "asr" => "video/x-ms-asf", "asx" => "video/x-ms-asf", "au" => "audio/basic", "avi" => "video/x-msvideo", "axs" => "application/olescript", "bas" => "text/plain", "bcpio" => "application/x-bcpio", "bin" => "application/octet-stream", "bmp" => "image/bmp", "c" => "text/plain", "cat" => "application/vnd.ms-pkiseccat", "cdf" => "application/x-cdf", "cer" => "application/x-x509-ca-cert", "class" => "application/octet-stream", "clp" => "application/x-msclip", "cmx" => "image/x-cmx", "cod" => "image/cis-cod", "cpio" => "application/x-cpio", "crd" => "application/x-mscardfile", "crl" => "application/pkix-crl", "crt" => "application/x-x509-ca-cert", "csh" => "application/x-csh", "css" => "text/css", "dcr" => "application/x-director", "der" => "application/x-x509-ca-cert", "dir" => "application/x-director", "dll" => "application/x-msdownload", "dms" => "application/octet-stream", "doc" => "application/msword", "dot" => "application/msword", "dvi" => "application/x-dvi", "dxr" => "application/x-director", "eps" => "application/postscript", "etx" => "text/x-setext", "evy" => "application/envoy", "exe" => "application/octet-stream", "fif" => "application/fractals", "flr" => "x-world/x-vrml", "gif" => "image/gif", "gtar" => "application/x-gtar", "gz" => "application/x-gzip", "h" => "text/plain", "hdf" => "application/x-hdf", "hlp" => "application/winhlp", "hqx" => "application/mac-binhex40", "hta" => "application/hta", "htc" => "text/x-component", "htm" => "text/html", "html" => "text/html", "htt" => "text/webviewhtml", "ico" => "image/x-icon", "ief" => "image/ief", "iii" => "application/x-iphone", "ins" => "application/x-internet-signup", "isp" => "application/x-internet-signup", "jfif" => "image/pipeg", "jpe" => "image/jpeg", "jpeg" => "image/jpeg", "jpg" => "image/jpeg", "js" => "application/x-javascript", "latex" => "application/x-latex", "lha" => "application/octet-stream", "lsf" => "video/x-la-asf", "lsx" => "video/x-la-asf", "lzh" => "application/octet-stream", "m13" => "application/x-msmediaview", "m14" => "application/x-msmediaview", "m3u" => "audio/x-mpegurl", "man" => "application/x-troff-man", "mdb" => "application/x-msaccess", "me" => "application/x-troff-me", "mht" => "message/rfc822", "mhtml" => "message/rfc822", "mid" => "audio/mid", "mny" => "application/x-msmoney", "mov" => "video/quicktime", "movie" => "video/x-sgi-movie", "mp2" => "video/mpeg", "mp3" => "audio/mpeg", "mpa" => "video/mpeg", "mpe" => "video/mpeg", "mpeg" => "video/mpeg", "mpg" => "video/mpeg", "mpp" => "application/vnd.ms-project", "mpv2" => "video/mpeg", "ms" => "application/x-troff-ms", "mvb" => "application/x-msmediaview", "nws" => "message/rfc822", "oda" => "application/oda", "p10" => "application/pkcs10", "p12" => "application/x-pkcs12", "p7b" => "application/x-pkcs7-certificates", "p7c" => "application/x-pkcs7-mime", "p7m" => "application/x-pkcs7-mime", "p7r" => "application/x-pkcs7-certreqresp", "p7s" => "application/x-pkcs7-signature", "pbm" => "image/x-portable-bitmap", "pdf" => "application/pdf", "pfx" => "application/x-pkcs12", "pgm" => "image/x-portable-graymap", "pko" => "application/ynd.ms-pkipko", "pma" => "application/x-perfmon", "pmc" => "application/x-perfmon", "pml" => "application/x-perfmon", "pmr" => "application/x-perfmon", "pmw" => "application/x-perfmon", "pnm" => "image/x-portable-anymap", "pot" => "application/vnd.ms-powerpoint", "ppm" => "image/x-portable-pixmap", "pps" => "application/vnd.ms-powerpoint", "ppt" => "application/vnd.ms-powerpoint", "prf" => "application/pics-rules", "ps" => "application/postscript", "pub" => "application/x-mspublisher", "qt" => "video/quicktime", "ra" => "audio/x-pn-realaudio", "ram" => "audio/x-pn-realaudio", "ras" => "image/x-cmu-raster", "rgb" => "image/x-rgb", "rmi" => "audio/mid", "roff" => "application/x-troff", "rtf" => "application/rtf", "rtx" => "text/richtext", "scd" => "application/x-msschedule", "sct" => "text/scriptlet", "setpay" => "application/set-payment-initiation", "setreg" => "application/set-registration-initiation", "sh" => "application/x-sh", "shar" => "application/x-shar", "sit" => "application/x-stuffit", "snd" => "audio/basic", "spc" => "application/x-pkcs7-certificates", "spl" => "application/futuresplash", "src" => "application/x-wais-source", "sst" => "application/vnd.ms-pkicertstore", "stl" => "application/vnd.ms-pkistl", "stm" => "text/html", "svg" => "image/svg+xml", "sv4cpio" => "application/x-sv4cpio", "sv4crc" => "application/x-sv4crc", "t" => "application/x-troff", "tar" => "application/x-tar", "tcl" => "application/x-tcl", "tex" => "application/x-tex", "texi" => "application/x-texinfo", "texinfo" => "application/x-texinfo", "tgz" => "application/x-compressed", "tif" => "image/tiff", "tiff" => "image/tiff", "tr" => "application/x-troff", "trm" => "application/x-msterminal", "tsv" => "text/tab-separated-values", "txt" => "text/plain", "uls" => "text/iuls", "ustar" => "application/x-ustar", "vcf" => "text/x-vcard", "vrml" => "x-world/x-vrml", "wav" => "audio/x-wav", "wcm" => "application/vnd.ms-works", "wdb" => "application/vnd.ms-works", "wks" => "application/vnd.ms-works", "wmf" => "application/x-msmetafile", "wps" => "application/vnd.ms-works", "wri" => "application/x-mswrite", "wrl" => "x-world/x-vrml", "wrz" => "x-world/x-vrml", "xaf" => "x-world/x-vrml", "xbm" => "image/x-xbitmap", "xla" => "application/vnd.ms-excel", "xlc" => "application/vnd.ms-excel", "xlm" => "application/vnd.ms-excel", "xls" => "application/vnd.ms-excel", "xlsx" => "vnd.ms-excel", "xlt" => "application/vnd.ms-excel", "xlw" => "application/vnd.ms-excel", "xof" => "x-world/x-vrml", "xpm" => "image/x-xpixmap", "xwd" => "image/x-xwindowdump", "z" => "application/x-compress", "zip" => "application/zip");
    // Get values after the "." (example."txt")
    $extension = end(explode('.', $file));
    // If unmatched or no "."
Example #15
0
function formatoImg($img)
{
    $mime = getMimeType($img);
    if (strpos("@" . $mime, "jpeg")) {
        return "jpg";
    }
    if (strpos("@" . $mime, "gif")) {
        return "gif";
    }
    if (strpos("@" . $mime, "png")) {
        return "png";
    }
    if (strpos("@" . $mime, "bmp")) {
        return "bmp";
    }
    if (file_exists($img)) {
        $fp = fopen($img, "r");
    }
    if ($fp) {
        $cabec = fread($fp, 10);
        if (strpos("@" . $cabec, "JFIF")) {
            return "jpg";
        }
        if (strpos("@" . $cabec, "GIF89")) {
            return "gif";
        }
        if (strpos("@" . $cabec, "PNG")) {
            return "png";
        }
        if (strpos("@" . $cabec, "BM")) {
            return "bmp";
        }
    }
    return "jpg";
}
         $message .= ucwords($field) . ": " . strip_tags($value) . "<br>";
     }
 }
 $attach = array();
 $file_name9 = basename($_FILES['datafile9']['name']);
 $data9 = file_get_contents($_FILES['datafile9']['tmp_name']);
 $file_contents9 = chunk_split(base64_encode($data9));
 $file_size9 = $_FILES['datafile9']['size'];
 $file_mime_type9 = getMimeType($_FILES['datafile9']['name']);
 for ($i = 1; $i <= $qtdeIntegrantes; $i++) {
     $file_name[$i] = basename($_FILES['datafile' . $i]['name']);
     $file_name[$i] = basename($_FILES['datafile' . $i]['name']);
     $data[$i] = file_get_contents($_FILES['datafile' . $i]['tmp_name']);
     $file_contents[$i] = chunk_split(base64_encode($data[$i]));
     $file_size[$i] = $_FILES['datafile' . $i]['size'];
     $file_mime_type[$i] = getMimeType($_FILES['datafile' . $i]['name']);
     $attach[] = array($_FILES['datafile' . $i]['tmp_name'], $file_mime_type[$i]);
 }
 $attach[] = array($_FILES['datafile9']['tmp_name'], $file_mime_type9);
 if (mimeTypeDenied($file_mime_type, $mimeTypesAllowed)) {
     if (deleteAllFiles('datafile', $qtdeIntegrantes)) {
         header("Location: http://tvcultura.cmais.com.br/preestreia/conjunto-2013?error=2");
         die;
     }
 } else {
     if (fileSizeDenied($file_size, $maxFileSize)) {
         if (deleteAllFiles('datafile', $qtdeIntegrantes)) {
             header("Location: http://tvcultura.cmais.com.br/preestreia/conjunto-2013?error=3");
             die;
         }
     } else {
Example #17
0
function validateImage($file, $field_name, $allowed_extensions)
{
    //$find_characters = array('!','@','#','$','%','^','&','*','(',')','+','=','[',']','\\','\'',';','/','{','}','|','"',':','<','>','?');
    $find_characters = array('\\', '/', ':', '*', '?', '"', '<', '>', '|');
    $max_size = ini_get('upload_max_filesize');
    //print_r($file);
    //exit;
    if (is_uploaded_file($file['tmp_name'])) {
        $filePath = $file['tmp_name'];
        $contentType = $file['type'];
    } elseif ($file['tmp_name'] != "") {
        $msg = str_replace('%field%', $field_name, _ALRT_FILE_ERROR);
        return $msg;
    }
    $find_dot_pos = strrpos($file['name'], '.');
    $fname = substr($file['name'], 0, $find_dot_pos);
    foreach ($find_characters as $key => $val) {
        if (strpos($fname, $val) !== False) {
            return _ALRT_FILE_NAME_ERROR;
        }
    }
    if (strtolower(substr($max_size, -1)) == 'm') {
        $max_size = substr($max_size, 0, strlen($max_size) - 1);
    }
    $max_size = $max_size * 1000 * 1024;
    if ($file['size'] == 0 || $file['size'] > $max_size) {
        $msg = str_replace('%field%', $field_name, _ALRT_CHECK_MAXSIZE);
        return $msg;
    }
    if (!checkLength($file['name'], 150)) {
        $msg = str_replace('%field%', $field_name, _ALRT_CHECK_LENGTH);
        return $msg;
    }
    if (!preg_match('#\\.(.+)$#', $file['name'], $matches)) {
        return _ALRT_FILE_EXT_ERROR;
    } else {
        if (!in_array(strtolower($matches[1]), $allowed_extensions)) {
            return _ALRT_IMAGE_TYPE_ERROR;
        }
    }
    $allowed_file_type = getMimeType($matches[1]);
    if (count($allowed_file_type) == 0 || !in_array($contentType, $allowed_file_type)) {
        return _ALRT_FILE_UPLOAD_ERROR;
    }
    return true;
}
Example #18
0
$videoFiles = array();
if ($dir = opendir($eventPath)) {
    while (($file = readdir($dir)) !== false) {
        $file = $eventPath . '/' . $file;
        if (is_file($file)) {
            if (preg_match('/-S([\\da-z]+)\\.(?:' . join('|', $videoFormats) . ')$/', $file, $matches)) {
                if ($matches[1] == $videoSize) {
                    $videoFiles[] = $file;
                }
            }
        }
    }
    closedir($dir);
}
if (isset($_REQUEST['download'])) {
    header("Content-type: " . getMimeType($videoFiles[$_REQUEST['download']]));
    header("Content-length: " . filesize($videoFiles[$_REQUEST['download']]));
    header("Content-disposition: attachment; filename=" . preg_replace("/^.*\\//", "", $videoFiles[$_REQUEST['download']]) . "; size=" . filesize($videoFiles[$_REQUEST['download']]));
    readfile($videoFiles[$_REQUEST['download']]);
    exit;
}
xhtmlHeaders(__FILE__, translate('Video') . ' - ' . $event['Name']);
?>
<body>
  <div id="page">
    <div id="content">
      <form method="post" action="<?php 
echo $_SERVER['PHP_SELF'];
?>
">
        <div class="hidden">
Example #19
0
function phpftp_view($ftp, $tempdir, $dir, $file)
{
    srand((double) microtime() * 1000000);
    $randval = rand();
    $tmpfile = "{$tempdir}/" . $file . "." . $randval;
    ftp_chdir($ftp, $dir);
    $remotefile = $dir . "/" . $file;
    if (!ftp_get($ftp, $tmpfile, $remotefile, FTP_BINARY)) {
        echo "tmpfile=\"{$tmpfile}\",file=\"{$remotefile}\"<BR>\n";
        macro_get_Link('newlogin', 'Start over?');
        $retval = 0;
    } else {
        $content_type = getMimeType($remotefile);
        header('Content-Type: ' . $content_type);
        readfile($tmpfile);
        $retval = 1;
    }
    @unlink($tmpfile);
    return $retval;
}
Example #20
0
/**
 * IMPORTANT TODO: check why performance on huge files is so bad (seeking-performance in large mixes is pretty poor compared to serving the mp3-mix directly)
 */
function deliver($file, $app)
{
    /**
     * Copyright 2012 Armand Niculescu - media-division.com
     * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
     * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
     * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
     * THIS SOFTWARE IS PROVIDED BY THE FREEBSD PROJECT "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     */
    //- turn off compression on the server
    @apache_setenv('no-gzip', 1);
    @ini_set('zlib.output_compression', 'Off');
    // sanitize the file request, keep just the name and extension
    $filePath = realpath($file);
    $pathParts = pathinfo($filePath);
    $fileName = $pathParts['basename'];
    $fileExt = $pathParts['extension'];
    if (is_file($filePath) === FALSE) {
        deliveryError(404);
    }
    // IMPORTANT TODO: proper check if file access is allowed
    if (stripos($filePath, $app->config['mpd']['alternative_musicdir']) !== 0) {
        deliveryError(401);
    }
    $file = @fopen($filePath, "rb");
    if (!$file) {
        deliveryError(500);
    }
    $fileSize = filesize($filePath);
    //check if http_range is sent by browser (or download manager)
    $range = '';
    if (isset($_SERVER['HTTP_RANGE'])) {
        @(list($size_unit, $range_orig) = @explode('=', $_SERVER['HTTP_RANGE'], 2));
        if ($size_unit == 'bytes') {
            //multiple ranges could be specified at the same time, but for simplicity only serve the first range
            //http://tools.ietf.org/id/draft-ietf-http-range-retrieval-00.txt
            @(list($range, $extra_ranges) = @explode(',', $range_orig, 2));
        } else {
            deliveryError(416);
        }
    }
    //figure out download piece from range (if set)
    @(list($seekStart, $seekEnd) = @explode('-', $range, 2));
    //set start and end based on range (if set), else set defaults
    //also check for invalid ranges.
    $seekEnd = empty($seekEnd) ? $fileSize - 1 : min(abs(intval($seekEnd)), $fileSize - 1);
    $seekStart = empty($seekStart) || $seekEnd < abs(intval($seekStart)) ? 0 : max(abs(intval($seekStart)), 0);
    //Only send partial content header if downloading a piece of the file (IE workaround)
    if ($seekStart > 0 || $seekEnd < $fileSize - 1) {
        header('HTTP/1.1 206 Partial Content');
        header('Content-Range: bytes ' . $seekStart . '-' . $seekEnd . '/' . $fileSize);
        header('Content-Length: ' . ($seekEnd - $seekStart + 1));
    } else {
        header("Content-Length: {$fileSize}");
    }
    // set the headers, prevent caching
    header("Pragma: public");
    header("Expires: -1");
    header("Cache-Control: public, must-revalidate, post-check=0, pre-check=0");
    // allow a file to be streamed instead of sent as an attachment
    // set appropriate headers for attachment or streamed file
    header("Content-Disposition: " . (isset($_REQUEST['stream']) ? 'attachment; filename="' . str_replace('"', '_', $fileName) . '"' : 'inline;'));
    header("Content-Type: " . getMimeType($fileName));
    header('Accept-Ranges: bytes');
    // do not block other requests of this client
    session_write_close();
    set_time_limit(0);
    fseek($file, $seekStart);
    while (!feof($file)) {
        print @fread($file, 1024 * 8);
        ob_flush();
        flush();
        if (connection_status() != 0) {
            @fclose($file);
            exit;
        }
    }
    @fclose($file);
    exit;
}
 $message = "Formulário Preenchido em " . date("d/m/Y") . " as " . date("H:i:s") . ", seguem abaixo os dados:<br><br>";
 while (list($field, $value) = each($_REQUEST)) {
     if (!in_array(ucwords($field), array('Form_action', 'X', 'Y', 'Enviar', 'Undefinedform_action'))) {
         $message .= ucwords($field) . ": " . strip_tags($value) . "<br>";
     }
 }
 $file_name1 = basename($_FILES['datafile1']['name']);
 $file_name2 = basename($_FILES['datafile2']['name']);
 $data1 = file_get_contents($_FILES['datafile1']['tmp_name']);
 $data2 = file_get_contents($_FILES['datafile2']['tmp_name']);
 $file_contents1 = chunk_split(base64_encode($data1));
 $file_contents2 = chunk_split(base64_encode($data2));
 $file_size1 = $_FILES['datafile1']['size'];
 $file_size2 = $_FILES['datafile2']['size'];
 $file_mime_type1 = getMimeType($_FILES['datafile1']['name']);
 $file_mime_type2 = getMimeType($_FILES['datafile2']['name']);
 $attach = array();
 $attach[] = array($_FILES['datafile1']['tmp_name'], $file_mime_type1);
 $attach[] = array($_FILES['datafile2']['tmp_name'], $file_mime_type2);
 if (!in_array($file_mime_type1, $mimeTypeAllowed) && !in_array($file_mime_type2, $mimeTypeAllowed)) {
     if (unlink($_FILES['datafile1']['tmp_name']) && unlink($_FILES['datafile2']['tmp_name'])) {
         header("Location: http://tvcultura.cmais.com.br/preestreia/solista-2013?error=2");
         die;
     }
 } else {
     if ($file_size1 > $maxFileSize || $file_size2 > $maxFileSize) {
         // 15MB
         if (unlink($_FILES['datafile1']['tmp_name']) && unlink($_FILES['datafile2']['tmp_name'])) {
             header("Location: http://tvcultura.cmais.com.br/preestreia/solista-2013?error=3");
             die;
         }
Example #22
0
function getMimeType($fileName, $path = false)
{
    if (apc_exists('MimeTypes')) {
        $types = apc_fetch('MimeTypes');
        $ext = pathinfo($fileName, PATHINFO_EXTENSION);
        if (!$ext) {
            $ext = $fileName;
        }
        $ext = strtolower($ext);
        return array_key_exists($ext, $types) ? $types[$ext] : null;
    } else {
        if ($path) {
            //Force refresh and try again
            refreshMime($path);
            return getMimeType($fileName);
        } else {
            return false;
        }
    }
}
Example #23
0
function outputVideoStream($id, $src, $width, $height, $format, $title = "")
{
    if (file_exists($src)) {
        $mimeType = getMimeType($src);
    } else {
        switch ($format) {
            case 'asf':
                $mimeType = "video/x-ms-asf";
                break;
            case 'avi':
            case 'wmv':
                $mimeType = "video/x-msvideo";
                break;
            case 'mov':
                $mimeType = "video/quicktime";
                break;
            case 'mpg':
            case 'mpeg':
                $mimeType = "video/mpeg";
                break;
            case 'swf':
                $mimeType = "application/x-shockwave-flash";
                break;
            case '3gp':
                $mimeType = "video/3gpp";
                break;
            default:
                $mimeType = "video/{$format}";
                break;
        }
    }
    if (!$mimeType || $mimeType == 'application/octet-stream') {
        $mimeType = 'video/' . $format;
    }
    $objectTag = false;
    if (ZM_WEB_USE_OBJECT_TAGS) {
        switch ($mimeType) {
            case "video/x-ms-asf":
            case "video/x-msvideo":
            case "video/mp4":
                if (isWindows()) {
                    ?>
<object id="<?php 
                    echo $id;
                    ?>
" width="<?php 
                    echo validNum($width);
                    ?>
" height="<?php 
                    echo validNum($height);
                    ?>
"
classid="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95"
codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,0,02,902"
standby="Loading Microsoft Windows Media Player components..."
type="<?php 
                    echo $mimeType;
                    ?>
">
<param name="FileName" value="<?php 
                    echo $src;
                    ?>
"/>
<param name="autoStart" value="1"/>
<param name="showControls" value="0"/>
<embed type="<?php 
                    echo $mimeType;
                    ?>
"
pluginspage="http://www.microsoft.com/Windows/MediaPlayer/"
src="<?php 
                    echo $src;
                    ?>
"
name="<?php 
                    echo validHtmlStr($title);
                    ?>
"
width="<?php 
                    echo validNum($width);
                    ?>
"
height="<?php 
                    echo validInt($height);
                    ?>
"
autostart="1"
showcontrols="0">
</embed>
</object>
<?php 
                    $objectTag = true;
                }
                break;
            case "video/quicktime":
                ?>
<object id="<?php 
                echo $id;
                ?>
" width="<?php 
                echo $width;
                ?>
" height="<?php 
                echo $height;
                ?>
"
classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B"
codebase="http://www.apple.com/qtactivex/qtplugin.cab"
type="<?php 
                echo $mimeType;
                ?>
">
<param name="src" value="<?php 
                echo $src;
                ?>
"/>
<param name="autoplay" VALUE="true"/>
<param name="controller" VALUE="false"/>
<embed type="<?php 
                echo $mimeType;
                ?>
"
src="<?php 
                echo $src;
                ?>
"
pluginspage="http://www.apple.com/quicktime/download/"
name="<?php 
                echo validHtmlStr($title);
                ?>
"
width="<?php 
                echo validInt($width);
                ?>
"
height="<?php 
                echo validInt($height);
                ?>
"
autoplay="true"
controller="true">
</embed>
</object>
<?php 
                $objectTag = true;
                break;
            case "application/x-shockwave-flash":
                ?>
<object id="<?php 
                echo $id;
                ?>
" width="<?php 
                echo $width;
                ?>
" height="<?php 
                echo $height;
                ?>
"
classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"
type="<?php 
                echo $mimeType;
                ?>
">
<param name="movie" value="<?php 
                echo $src;
                ?>
"/>
<param name="quality" value="high"/>
<param name="bgcolor" value="#ffffff"/>
<embed type="<?php 
                echo $mimeType;
                ?>
"
pluginspage="http://www.macromedia.com/go/getflashplayer"
src="<?php 
                echo $src;
                ?>
"
name="<?php 
                echo validHtmlStr($title);
                ?>
"
width="<?php 
                echo validInt($width);
                ?>
"
height="<?php 
                echo validInt($height);
                ?>
"
quality="high"
bgcolor="#ffffff">
</embed>
</object>
<?php 
                $objectTag = true;
                break;
        }
    }
    if (!$objectTag) {
        ?>
<embed<?php 
        echo isset($mimeType) ? ' type="' . $mimeType . '"' : "";
        ?>
 
src="<?php 
        echo $src;
        ?>
"
name="<?php 
        echo validHtmlStr($title);
        ?>
"
width="<?php 
        echo validInt($width);
        ?>
"
height="<?php 
        echo validInt($height);
        ?>
"
autostart="1"
autoplay="1"
showcontrols="0"
controller="0">
</embed>
<?php 
    }
}
function multi_send_mail($mailto, $subject, $body, $mailfrom, $errorMailTo, $files = array())
{
    $boundary = md5(uniqid(rand()));
    //バウンダリー文字(パートの境界)
    $header = "From: {$mailfrom}\n";
    $header .= "Reply-To: {$mailfrom}\n";
    $header .= "X-Mailer: PHP/" . phpversion() . "\n";
    $header .= "MIME-version: 1.0\n";
    //アップファイルがあるか
    $multipartFlag = 0;
    if (is_array($files)) {
        foreach ($files as $fileItem => $file) {
            if (file_exists($file)) {
                $multipartFlag++;
                break;
            }
        }
    }
    //アップファイルの有無でヘッダを変更
    if ($multipartFlag) {
        $header .= "Content-Type: multipart/mixed;\n";
        $header .= "\tboundary=\"{$boundary}\"\n";
        $msg .= "This is a multi-part message in MIME format.\n\n";
        $msg .= "--{$boundary}\n";
        $msg .= "Content-Type: text/plain; charset=ISO-2022-JP\n";
        $msg .= "Content-Transfer-Encoding: 7bit\n\n";
        $body = $msg . $body;
    } else {
        $header .= "Content-Type: text/plain; charset=ISO-2022-JP\n";
        $header .= "Content-Transfer-Encoding: 7bit\n";
    }
    //添付ファイルをbodyに追加
    if (is_array($files)) {
        foreach ($files as $fileItem => $file) {
            $fp = fopen($file, "r") or die("error");
            //ファイルの読み込み
            $contents = fread($fp, filesize($file));
            fclose($fp);
            $upfile_name = basename($file);
            $upfile_type = getMimeType(basename($file));
            $f_encoded = chunk_split(base64_encode($contents));
            //エンコードして分割
            $body .= "\n--{$boundary}\n";
            $body .= "Content-Type: " . $upfile_type . ";\n";
            $body .= "\tname=\"{$upfile_name}\"\n";
            $body .= "Content-Transfer-Encoding: base64\n";
            $body .= "Content-Disposition: attachment;\n";
            $body .= "\tfilename=\"{$upfile_name}\"\n\n";
            $body .= "{$f_encoded}\n";
        }
    }
    if ($multipartFlag) {
        $body .= "--{$boundary}--";
    }
    if ($errorMailTo) {
        $errorMailTo = "-f " . $errorMailTo;
    }
    //
    //mb_encode_mimeheader($subject,"ISO-2022-JP","B","\n");
    //$subject = mb_convert_encoding($subject,"UTF-8",mb_detect_encoding($subject));
    if (mail($mailto, mb_encode_mimeheader($subject, "ISO-2022-JP", "B", "\n"), mb_convert_encoding($body, "ISO-2022-JP"), $header, $errorMailTo)) {
        return true;
    } else {
        return false;
    }
}
 /**
  * Get the image's mime type.
  *
  * @return string
  */
 public function get_mime_type()
 {
     return getMimeType($this->get_image_filename(), $this->get_ext());
 }
Example #26
0
$assetPath = dirname(__FILE__) . '/../';
require_once $assetPath . '../config/config.web.php';
$files = $_SERVER['QUERY_STRING'];
$split = '__';
$str = '';
$len = 7;
// len for '/combo/'
$file = md5($files);
$real = ROOT . "/tmp/{$file}";
$alias = "combine/{$file}";
list($files) = explode('?', $files);
//$tmp        = substr($files, $len);
$tmp = $files;
//$tmp        = ltrim(strstr($tmp, '/'), '/');
$files = explode($split, $tmp);
header('Content-Type: ' . getMimeType($assetPath . $files[0]));
if (file_exists($real)) {
    $mtime = filemtime($real);
    $old = false;
    foreach ($files as $k => $v) {
        if (is_numeric($v) or empty($v)) {
            unset($files[$k]);
            continue;
        }
        $filepath = $assetPath . $v;
        if (!is_file($filepath)) {
            die;
        }
        if (filemtime($filepath) > $mtime) {
            $old = true;
            break;
Example #27
0
function upload($filePath, $destinationDir = 'images', array $allowedMimes = array())
{
    if (!is_file($filePath) || !is_dir($destinationDir)) {
        return false;
    }
    if (!($mime = getMimeType($filePath))) {
        return false;
    }
    if (!in_array($mime, $allowedMimes)) {
        return false;
    }
    $ext = null;
    $extMapping = getExtensionToMimeTypeMapping();
    foreach ($extMapping as $extension => $mimeType) {
        if ($mimeType == $mime) {
            $ext = $extension;
            break;
        }
    }
    if (empty($ext)) {
        $ext = pathinfo($filePath, PATHINFO_EXTENSION);
    }
    if (empty($ext)) {
        return false;
    }
    $fileName = md5(uniqid(rand(0, time()), true)) . '.' . $ext;
    $newFilePath = $destinationDir . '/' . $fileName;
    if (!rename($filePath, $newFilePath)) {
        return false;
    }
    return $fileName;
}
Example #28
0
    function object()
    {
        if (!MRights::can("open")) {
            return $this->_noAuth("open");
        }
        //video
        global $dir;
        $info = MFile::info($dir);
        $this->view->add2Content('<center>
		        <object align="middle"  type="' . getMimeType($dir) . '" data="' . MURL::_("xhrvideo", urlencode(str_replace(_START_FOLDER, "", $dir))) . '" width="750px" height="450px">
				</object></center>');
    }
Example #29
0
 /**
  * Makes sure the file type / extension is valid using a couple of methods
  */
 public function checkFileTypes()
 {
     if ($this->errors || !$this->params['fileTypes']) {
         return;
     }
     $ext = $this->getExtFromFilename();
     $types = $this->params['fileTypes'] = array_filter($this->params['fileTypes']);
     $mime = getMimeType($this->uploaded_file) ?: $this->getMimeByExtension($ext);
     $in_filetypes = false;
     if ($mime) {
         foreach ($types as $v) {
             $v = $this->getMimeByExtension($v);
             if ($v == $mime) {
                 $in_filetypes = true;
                 break;
             }
         }
     }
     if (!$in_filetypes) {
         $this->errors[] = 'You cannot upload type: <strong>' . $ext . '</strong>';
     }
 }
Example #30
-1
function isVideo($file)
{
    $mime = getMimeType("files/" . $file);
    if (strstr($mime, "video/")) {
        return true;
    } else {
        return false;
    }
}