body {font-size:90%} .field {text-align:right} .note {font-size:90%; color:#808080} </style> <?php if (isset($_FILES['FileName']) and $_FILES['FileName'] != '') { //proc upload $filename = $_FILES['FileName']['tmp_name']; $path = $cfg_web_root . 'media/'; //make the dirs if (!file_exists($path)) { mkdir($path, 0744); } //move original file $imageInfo = getimagesize($_FILES['FileName']['tmp_name']); $destName = unique_filename($_FILES['FileName']['name']); $destPath = $path . $destName; $worked = move_uploaded_file($_FILES['FileName']['tmp_name'], $destPath); if (!$worked) { echo "Failed to copy file to: " . $path . $_FILES['FileName']['name']; exit; } if (isset($_POST['border']) and $_POST['border'] == 1) { $class = 'class="image_brd"'; } else { $class = 'class="image_no_brd"'; } $html = '<img width="' . $imageInfo[0] . '" height="' . $imageInfo[1] . '" alt="' . $_POST['alt'] . '" src="' . $configObject->get('cfg_root_path') . '/media/' . $destName . '" ' . $class . ' />'; ?> <script type="text/javascript" src="../../tiny_mce_popup.js"></script> <script>
public function metaWeblog_newMediaObject($args) { $this->auth($args[1], $args[2]); $config = Config::current(); $file = unique_filename(trim($args[3]['name'], ' /')); $path = MAIN_DIR . $config->uploads_path . $file; if (file_put_contents($path, $args[3]['bits']) === false) { return new IXR_Error(500, __("Failed to write file.")); } $url = $config->chyrp_url . $config->uploads_path . str_replace('+', '%20', urlencode($file)); Trigger::current()->filter($url, 'metaWeblog_newMediaObject', $path); return array('url' => $url); }
/** * Function: upload * Moves an uploaded file to the uploads directory. * * Parameters: * $file - The $_FILES value. * $extension - An array of valid extensions (case-insensitive). * $path - A sub-folder in the uploads directory (optional). * $put - Use copy() instead of move_uploaded_file()? * * Returns: * The resulting filename from the upload. */ function upload($file, $extension = null, $path = "", $put = false) { $file_split = explode(".", $file['name']); $dir = rtrim(MAIN_DIR . Config::current()->uploads_path . $path, "/"); if (!file_exists($dir)) { mkdir($dir, 0777, true); } $original_ext = end($file_split); # Handle "double extensions" foreach (array("tar.gz", "tar.bz", "tar.bz2") as $ext) { list($first, $second) = explode(".", $ext); $file_first =& $file_split[count($file_split) - 2]; if ($file_first == $first and end($file_split) == $second) { $file_first = $first . "." . $second; array_pop($file_split); } } $file_ext = end($file_split); if (is_array($extension)) { if (!in_array(strtolower($file_ext), $extension) and !in_array(strtolower($original_ext), $extension)) { $list = ""; for ($i = 0; $i < count($extension); $i++) { $comma = ""; if ($i + 1 != count($extension)) { $comma = ", "; } if ($i + 2 == count($extension)) { $comma = ", and "; } $list .= "<code>*." . $extension[$i] . "</code>" . $comma; } error(__("Invalid Extension"), _f("Only %s files are accepted.", array($list))); } } elseif (isset($extension) and strtolower($file_ext) != strtolower($extension) and strtolower($original_ext) != strtolower($extension)) { error(__("Invalid Extension"), _f("Only %s files are supported.", array("*." . $extension))); } array_pop($file_split); $file_clean = implode(".", $file_split); $file_clean = sanitize($file_clean, false) . "." . $file_ext; $filename = unique_filename($file_clean, $path); $message = __("Couldn't upload file. CHMOD <code>" . $dir . "</code> to 777 and try again. If this problem persists, it's probably timing out; in which case, you must contact your system administrator to increase the maximum POST and upload sizes."); if ($put) { if (!@copy($file['tmp_name'], $dir . "/" . $filename)) { error(__("Error"), $message); } } elseif (!@move_uploaded_file($file['tmp_name'], $dir . "/" . $filename)) { error(__("Error"), $message); } return $path ? $path . "/" . $filename : $filename; }
function ParseImages($text) { global $import_directory; global $q_warnings; global $q_errors; if (stripos(" " . $text, "<img") > 0) { $output = ''; while ($text) { if (stripos(" " . $text, "<img") > 0) { $pre = substr($text, 0, stripos($text, "<img")); $imgtag = substr($text, stripos($text, "<img")); $imgtag = substr($imgtag, 0, stripos($imgtag, ">") + 1); $rest = substr($text, stripos($text, "<img")); $rest = substr($rest, stripos($rest, ">") + 1); $output .= $pre; // we have a src tag? if (stripos($imgtag, "src") > 0) { $data = parseHtml($imgtag); $src = $data['IMG'][0]['src']; $basename = basename($src); $filename = FindFile($import_directory, $basename); if ($filename) { $basename = basename($filename); $uniqueFilename = unique_filename($basename); copy($import_directory . "/" . $filename, $cfg_web_root . 'media/' . $uniqueFilename); $data['IMG'][0]['src'] = "/media/" . $basename; // recreate img tag $imgtag = "<img "; foreach ($src = $data['IMG'][0] as $tag => $value) { $imgtag .= "{$tag}=\"{$value}\" "; } $imgtag .= "/>"; } else { $q_warnings[] = "Missing image {$basename}"; } } $output .= $imgtag; $text = $rest; } else { $output .= $text; $text = ""; } } $text = $output; } return $text; }
} } $image_part++; } } else { $new_q_media = ''; } } // Option data if (trim($o_media) != '') { $media_array = array(); $media_array = explode('|', $o_media); $new_o_media = ''; foreach ($media_array as $individual_media) { if (trim($individual_media) != '' and trim($individual_media) != 'NULL') { $new_media_name = unique_filename($individual_media); if (file_exists("../media/{$individual_media}")) { if (!copy("../media/{$individual_media}", "../media/{$new_media_name}")) { $error[] = sprintf($string['copyerror'], $individual_media); //if the image is missing don't put the file name in the new question $new_media_name = ''; } } else { $new_media_name = ''; } if ($new_o_media == '') { $new_o_media = $new_media_name; } else { $new_o_media .= '|' . $new_media_name; } }
function video_snapshot_symlink($args) { $obj = $args['obj']; if (!isset($obj['type']) || $obj['type'] != 'video') { return false; } $dest_dir = CONTENT_DIR . '/' . array_shift(expl('.', $obj['name'])) . '/shared'; $src_file = CONTENT_DIR . '/' . array_shift(expl('.', $args['origin'])) . '/shared/' . $obj['video-file']; if (($f = dir_has_same_file($dest_dir, $src_file)) !== false) { $obj['video-file'] = $f; } else { // copy file $dest_file = $dest_dir . '/' . unique_filename($dest_dir, $src_file); $m = umask(0111); if (!@copy($src_file, $dest_file)) { umask($m); log_msg('error', 'video_snapshot_symlink: error copying referenced file ' . quot($src_file) . ' to ' . quot($dest_file)); return false; } umask($m); $obj['video-file'] = basename($dest_file); log_msg('info', 'video_snapshot_symlink: copied referenced file to ' . quot($dest_file)); } $ret = save_object($obj); if ($ret['#error']) { log_msg('error', 'video_snapshot_symlink: error saving object ' . quot($obj['name'])); return false; } else { return true; } }
/** * implements snapshot_symlink * * see snapshot() in module_glue.inc.php */ function image_snapshot_symlink($args) { $obj = $args['obj']; if (!isset($obj['type']) || $obj['type'] != 'image') { return false; } // consider the following: // * an image object is on page a, which at some point got distributed to all // other pages through symlinks // * we are now creating a snapshot of any page b, come across the symlink // pointing to an object and page a // in this case we don't copy the symlink but the current content of the // object, as we by all means want to preserve the current _state_ we copy // the symlink's content (this happens in snapshot() in module_glue.inc.php) // - thus turning it into a first-class object on the new snapshot-page // because of this we need to copy any referenced files as well from the // shared directory in page a to the one on page b, this happens in this // hook $dest_dir = CONTENT_DIR . '/' . array_shift(expl('.', $obj['name'])) . '/shared'; $src_dir = CONTENT_DIR . '/' . array_shift(expl('.', $args['origin'])) . '/shared'; // we do this for image-file and image-resized-file // .. to add a bit of complexity ;) foreach (array('image-file', 'image-resized-file') as $field) { if (empty($obj[$field])) { continue; } else { $src_file = $src_dir . '/' . $obj[$field]; } if (($f = dir_has_same_file($dest_dir, $src_file)) !== false) { $obj[$field] = $f; } else { // copy file $dest_file = $dest_dir . '/' . unique_filename($dest_dir, $src_file); $m = umask(0111); if (!@copy($src_file, $dest_file)) { umask($m); log_msg('error', 'image_snapshot_symlink: error copying referenced file ' . quot($src_file) . ' to ' . quot($dest_file)); return false; } umask($m); $obj[$field] = basename($dest_file); log_msg('info', 'image_snapshot_symlink: copied referenced file to ' . quot($dest_file)); } } // save changes in the object $ret = save_object($obj); if ($ret['#error']) { log_msg('error', 'image_snapshot_symlink: error saving object ' . quot($obj['name'])); return false; } else { return true; } }
/** * move an uploaded file to the shared directory of a page * * this function reuses existing files when possible. * @param string $fn filename of newly uploaded file (most likely in /tmp) * @param string $page page or pagename * @param string $orig_fn the original filename on the client machine (optional) * @param bool &$existed set to true if the filename returned did already exist * before * @return filename inside the shared directory or false in case of error */ function upload_file($fn, $page, $orig_fn = '', &$existed = false) { // default to the temporary filename if ($orig_fn == '') { $orig_fn = $fn; } $a = expl('.', $page); if (count($a) < 1 || !is_dir(CONTENT_DIR . '/' . $a[0])) { log_msg('error', 'common: page ' . quot($page) . ' does not exist, cannot move uploaded file'); // not sure if we ought to remove the file in /tmp here (probably not) return false; } // create shared directory if it doesn't exist yet $d = CONTENT_DIR . '/' . $a[0] . '/shared'; if (!is_dir($d)) { $m = umask(00); if (!@mkdir($d, 0777)) { umask($m); log_msg('error', 'common: cannot create shared directory ' . quot($d) . ', cannot move uploaded file'); // not sure if we ought to remove the file in /tmp here (probably not) return false; } umask($m); } // check if file is already in shared directory if (($f = dir_has_same_file($d, $fn, $orig_fn)) !== false) { log_msg('info', 'common: reusing file ' . quot($f) . ' instead of newly uploaded file as they don\'t differ'); @unlink($fn); $existed = true; return $f; } else { // at least give it a unique name $f = unique_filename($d, basename($orig_fn)); $m = umask(0111); if (!@move_uploaded_file($fn, $d . '/' . $f)) { umask($m); log_msg('error', 'common: error moving uploaded file to ' . quot($d . '/' . $f)); // not sure if we ought to remove the file in /tmp here (probably not) return false; } else { umask($m); log_msg('info', 'common: moved uploaded file to ' . quot($d . '/' . $f)); $existed = false; return $f; } } }
<title>New Captivate Tutorial</title> <link rel="stylesheet" type="text/css" href="../../css/body.css" /> <style type="text/css"> body {background-color:#EEECDC; font-size:90%} </style> <?php if ($_FILES['FileName'] != '') { //proc upload $filename = $_FILES['FileName']['tmp_name']; //make the dirs if (!file_exists($path)) { mkdir($path, 0744); } //move orignal file $unique_name = unique_filename($_FILES['FileName']['name'], $path); $worked = move_uploaded_file($_FILES['FileName']['tmp_name'], $path . $unique_name); if (!$worked) { echo "Failed to copy file to: " . $path . $_FILES['FileName']['name']; exit; } $html = '<div> <table style="CURSOR: pointer" onclick="openTutorial(\'' . $_FILES['FileName']['name'] . '\')" border="0" cellspacing="0" cellpadding="0"> <tbody> <tr><td rowspan="2" style="width:70px"><img border="0" alt="Demo Movie" src="./large_play_icon.png" width="64" height="64" alt="play" /></td><td><div style="font-size:125%; color:blue">' . $_POST['title'] . '</div><div style="font-size:90%; color:#808080">Flash required</div></td></tr> </tbody> </table> </div>'; ?> <script type="text/javascript" language="javascript"> function retunHtmlToMainWindow() {
/** * IMPORT: Copy a file from the temportary directory to the /media directory. */ private function copy_images($dir, $tmp_path) { $configObj = Config::get_instance(); if ($handle = opendir($dir)) { while (false !== ($entry = readdir($handle))) { if ($entry != '.' and $entry != '..' and $entry != 'raf.json') { $new_media = unique_filename($entry); rename($tmp_path . $this->userID . '/' . $entry, $this->configObj->get('cfg_web_root') . 'media/' . $new_media); $this->data = str_replace($entry, $new_media, $this->data); } } closedir($handle); } }