示例#1
0
function et_media_handle_upload($imageurl, $post_id, $post_data = array(), $overrides = array('test_form' => false))
{
    $time = current_time('mysql');
    /*    if ( $post = get_post($post_id) ) {
            if ( substr( $post->post_date, 0, 4 ) > 0 )
                $time = $post->post_date;
        }
    
    */
    $temp = explode('/', $imageurl);
    $name = trim($temp[count($temp) - 1]);
    /*    $name = $_FILES[$file_id]['name'];
        $file = wp_handle_upload($_FILES[$file_id], $overrides, $time);
    
        if ( isset($file['error']) )
            return new WP_Error( 'upload_error', $file['error'] );
    
        $name_parts = pathinfo($name);
        $name = trim( substr( $name, 0, -(1 + strlen($name_parts['extension'])) ) );
    */
    //$url = $file['url'];
    $url = 'http://' . $_SERVER['HTTP_HOST'] . $imageurl;
    //    $type = $file['type'];
    $path = dirname(realpath($_SERVER['SCRIPT_FILENAME']));
    $path = $path . '/..' . $imageurl;
    $type = mime($path);
    if ($type == '') {
        $type = 'image/*';
    }
    //$file = $file['file'];
    $file = $path;
    $title = $name;
    $content = '';
    // use image exif/iptc data for title and caption defaults if possible
    if ($image_meta = @wp_read_image_metadata($file)) {
        if (trim($image_meta['title']) && !is_numeric(sanitize_title($image_meta['title']))) {
            $title = $image_meta['title'];
        }
        if (trim($image_meta['caption'])) {
            $content = $image_meta['caption'];
        }
    }
    // Construct the attachment array
    $attachment = array_merge(array('post_mime_type' => $type, 'guid' => $url, 'post_parent' => $post_id, 'post_title' => $title, 'post_content' => $content), $post_data);
    // This should never be set as it would then overwrite an existing attachment.
    if (isset($attachment['ID'])) {
        unset($attachment['ID']);
    }
    // Save the data
    $id = wp_insert_attachment($attachment, $file, $post_id);
    if (!is_wp_error($id)) {
        wp_update_attachment_metadata($id, wp_generate_attachment_metadata($id, $file));
    }
    return $id;
}
示例#2
0
 function mime_content_type($file)
 {
     return mime($file);
 }
示例#3
0
/**
 * 根据mime获取扩展名
 * @param string $mime mime字串,例如image/gif
 * @return string
 */
function mime2ext($mime)
{
    $mimes = mime();
    if (empty($mimes[$mime])) {
        return '';
    }
    return current(explode(' ', $mimes[$mime]));
}
示例#4
0
<?php

$obj = db_single('select * from sitewiki_file where page_id = ? and id = ?', $parameters['page'], $parameters['file']);
if (!$obj) {
    die('File not found!');
}
header('Content-Type: ' . mime($obj->name));
header('Content-Disposition: inline; filename=' . $obj->name);
header('Content-Length: ' . filesize('inc/app/sitewiki/data/' . $obj->page_id . '_' . $obj->id));
readfile('inc/app/sitewiki/data/' . $obj->page_id . '_' . $obj->id);
exit;
示例#5
0
        //header ('Content-Disposition: inline; filename=' . $info['basename'] . '.' . $info['extension']);
        //echo @join ('', @file ('inc/data/' . $parameters['file']));
        if ($fh = fopen('inc/data/' . $parameters['file'], 'rb')) {
            fseek($fh, $from);
            $cur_pos = ftell($fh);
            while ($cur_pos !== false && ftell($fh) + $bufsize < $to + 1) {
                $buffer = fread($fh, $bufsize);
                echo $buffer;
                $cur_pos = ftell($fh);
            }
            $buffer = fread($fh, $to + 1 - $cur_pos);
            echo $buffer;
            fclose($fh);
        } else {
            header('HTTP/1.1 404 Not Found');
        }
    } else {
        header('HTTP/1.1 500 Internal Server Error');
    }
} else {
    // give 'em the file
    header('Cache-control: private');
    header('Content-Type: ' . str_replace('|[,;].*$|i', '', mime('inc/data/' . $parameters['file'])));
    header('Content-Disposition: inline; filename="' . basename($parameters['file']) . '"');
    header('Content-Length: ' . filesize('inc/data/' . $parameters['file']));
    //echo @join ('', @file ('inc/data/' . $parameters['file']));
    readfile('inc/data/' . $parameters['file']);
}
//loader_import ('sitetracker.Bug');
db_execute('insert into sitellite_filesystem_download values (?, now(), ?)', $parameters['file'], $_SERVER['REMOTE_ADDR']);
exit;
示例#6
0
<?php

if (!path('root')) {
    die('Restrict');
}
$app = new \Slim\Slim(array('mode' => env(), 'templates.path' => path('app.view'), 'view' => new \Slimkeleton\View\Mustache()));
// Only invoked if mode is "production"
$app->configureMode('production', function () use($app) {
    $app->config(array('log.enable' => true, 'log.level' => \Slim\Log::WARN, 'debug' => false));
});
// Only invoked if mode is "development"
$app->configureMode('development', function () use($app) {
    $app->config(array('log.enable' => false, 'log.level' => \Slim\Log::DEBUG, 'debug' => true));
});
// enable cross domain
$app->response()->header('Access-Control-Allow-Origin', '*');
$app->response()->header('Access-Control-Allow-Methods', 'POST, GET, OPTIONS, PUT, DELETE');
$app->response()->header('Access-Control-Allow-Headers', 'Content-Type, X-Requested-With, X-PINGOTHER');
$app->response()->header('Access-Control-Allow-Credentials', 'true');
$app->response()->header('Access-Control-Max-Age', 86400);
// all methods return json content
$app->response()->header('Content-Type', mime('txt'));
// replace 404
$app->notFound(function () use($app) {
    echo json_encode(array('error' => 404, 'message' => 'not found'));
});
// replace ERROR
$app->error(function (\Exception $e) use($app) {
    echo json_encode(array('error' => 500, 'message' => $e->getMessage()));
});
示例#7
0
 /**
  * try to detect the mime type of a file
  *
  * @param  string  file path
  * @return string  guessed mime type
  */
 function _mimetype($fspath)
 {
     if (@is_dir($fspath)) {
         return 'httpd/unix-directory';
     }
     return mime($fspath, 'application/octet-stream');
 }
示例#8
0
     }
     $team_list = session_allowed_teams_list();
     if (!in_array('all', $team_list)) {
         $params['sitellite_team'] = new rList('sitellite_team', $team_list);
     }
     // perform the search
     $res = $rex->getStoreList($params);
     // build the result object
     $out = new StdClass();
     $out->query = $parameters['query'];
     $out->results = count($res);
     $out->files = array();
     foreach ($res as $row) {
         $info = $rex->getCurrent($row->name);
         unset($info->body);
         $out->files[] = (object) array('type' => mime($info->name), 'name' => '/' . $info->name, 'size' => $info->filesize, 'created' => $info->date_created, 'modified' => $info->last_modified, 'keywords' => $info->keywords, 'description' => $info->description, 'access' => $info->sitellite_access, 'status' => $info->sitellite_status, 'team' => $info->sitellite_team, 'owner' => $info->sitellite_owner, 'lock' => webfiles_lock($info->name));
     }
     webfiles_response($out);
     break;
 case 'lock':
     $path = webfiles_request();
     if (!file_exists($prefix . $path)) {
         webfiles_error(404, 'Not found');
     }
     //if (is_dir ($prefix . $path)) {
     //	webfiles_error (500, 'Locks not supported on directories');
     //}
     // it's someone else's lock
     $lock = webfiles_lock($path);
     if ($lock && $lock->owner != session_username()) {
         webfiles_error(409, 'Conflict');
    echo "Rien à afficher\n";
    exit(1);
}
$filenames = $doc->getDocumentFormats();
foreach ($doc->listeAnnexe() as $format) {
    $filenames[] = "annexes/" . $format;
}
if (!in_array($fic, $filenames)) {
    echo "Format demandé inconnu\n";
    exit(1);
}
$fichier = PATH_SITE_ROOT . $doc->getDocumentPath() . '/' . $fic;
$mime = mime($fichier);
if ($mime == 'application/x-httpd-php') {
    header('Content-disposition: inline; filename="' . $id . '.html"');
    include $fichier;
} else {
    header('Content-type: ' . mime($fichier));
    header('Content-disposition: inline; filename="' . $id . '.' . substr(strrchr($fic, "."), 1) . '"');
    openfic($fichier);
}
function openfic($filename)
{
    if (!($fp = @fopen($filename, "r"))) {
        return false;
    }
    $res = fread($fp, filesize($filename));
    fclose($fp);
    print $res;
    return true;
}