Exemplo n.º 1
0
function addFileToEntity()
{
    global $pageno, $etype_by_pageno;
    if (!isset($etype_by_pageno[$pageno])) {
        throw new RackTablesError('key not found in etype_by_pageno', RackTablesError::INTERNAL);
    }
    $realm = $etype_by_pageno[$pageno];
    assertStringArg('comment', TRUE);
    // Make sure the file can be uploaded
    if (get_cfg_var('file_uploads') != 1) {
        throw new RackTablesError('file uploads not allowed, change "file_uploads" parameter in php.ini', RackTablesError::MISCONFIGURED);
    }
    // Exit if the upload failed
    if ($_FILES['file']['error']) {
        showFuncMessage(__FUNCTION__, 'ERR1', array($_FILES['file']['error']));
        return;
    }
    $fp = fopen($_FILES['file']['tmp_name'], 'rb');
    global $sic;
    commitAddFile($_FILES['file']['name'], $_FILES['file']['type'], $fp, $sic['comment']);
    usePreparedInsertBlade('FileLink', array('file_id' => lastInsertID(), 'entity_type' => $realm, 'entity_id' => getBypassValue()));
    showFuncMessage(__FUNCTION__, 'OK', array(htmlspecialchars($_FILES['file']['name'])));
}
Exemplo n.º 2
0
 * from a local mirror of XKCD archive, if there is one.
 *
 * First, it is necessary to get the files themselves. It was possible
 * earlier to do that with a single wget pass:
 * $ wget -r -A png http://imgs.xkcd.com/comics/
 * However, after changes on the XKCD server more work is necessary:
 * $ wget --mirror --level=2 --span-hosts --domains=xkcd.com,imgs.xkcd.com --accept=html,jpg,png http://xkcd.com/archive/
 * There should be several hundred PNG and JPEG pictures in the imgs.xkcd.com/comics
 * directory after that. (There are other XKCD ripping scripts available
 * on the Internet.)
 *
 * Second, two variables below ($imgdir and $racktables_root) must be set
 * according to local filesystem layout. After that the script can be
 * executed from command-line (php XKCD-files.php) to import the files.
 */
# the line below prevents unintentional changes to DB
exit;
$imgdir = '/tmp/imgs.xkcd.com/comics';
$racktables_root = '/var/www/vhosts/racktables.org/demo/trunk';
$mimetype = array('png' => 'image/png', 'jpg' => 'image/jpeg');
chdir($racktables_root);
$script_mode = TRUE;
include 'inc/init.php';
foreach (array('png', 'jpg') as $ext) {
    foreach (glob("{$imgdir}/*.{$ext}") as $longname) {
        echo "{$longname} : ";
        $data = file_get_contents($longname);
        commitAddFile(basename($longname), $mimetype[$ext], $data, 'XKCD (http://xkcd.com/)');
        echo "OK \n";
    }
}