{ set_time_limit(0); if (is_file($path) === true) { $file = fopen($path, 'r'); $temp = tempnam('./', 'tmp'); if (is_resource($file) === true) { while (feof($file) === false) { file_put_contents($temp, str_replace($string, $replace, fgets($file)), FILE_APPEND); } fclose($file); } unlink($path); } return rename($temp, $path); } replace_file($filename, $includecontent, ''); // Now add back include line if (is_writable($filename)) { if (!($handle = fopen($filename, 'a'))) { echo "Cannot open file ({$filename})"; exit; } // Write $somecontent to our opened file. if (fwrite($handle, $includecontent) === FALSE) { echo "Cannot write to file ({$filename})"; exit; } echo "<br>Success, wrote ({$includecontent})<br> to file ({$filename})<br><br>"; fclose($handle); } else { echo "The file {$filename} is not writable";
/** * replace_attachment * * * * * * */ function replace_attachment($location, $new, $current) { $replacement = replace_file($location, $new, $current); if (!is_array($replacement)) { return $replacement; } $conn = author_connect(); $query = "UPDATE attachments SET size = '" . (int) $replacement['size'] . "', \n\t\t\t\t\t\t\t\t\text = '" . $conn->real_escape_string($replacement['ext']) . "',\n\t\t\t\t\t\t\t\t\tmime = '" . $conn->real_escape_string($replacement['mime']) . "'\n\t\t\t\t\t\t\t\t\tWHERE filename LIKE '" . $conn->real_escape_string($replacement['filename']) . "'"; $conn->query($query); return true; }
include_once WW_ROOT . '/ww_config/author_controller_functions.php'; include_once WW_ROOT . '/ww_config/author_view_functions.php'; // get image details $image_id = isset($_GET['image_id']) ? (int) $_GET['image_id'] : ''; // process edited image $edit_success = 0; if (isset($_POST['submit'])) { $edit = update_image($image_id); $edit_success = $edit == false ? 0 : 1; } // replace thumbnail if (isset($_POST['replace_thumb'])) { if (isset($_FILES['new_thumb']) && empty($_FILES['new_thumb']['error'])) { $current = $_POST['current_thumb']; $new = $_FILES['new_thumb']; $thumb_error = replace_file($current, $new); if (is_array($thumb_error)) { header('Location: ' . $url); } } } // get image details $image = get_image($image_id); $image_src = ' <img src="' . $image['src'] . '" alt="' . $image['alt'] . '" title="' . $image['title'] . '" width="' . $image['width'] . '" height="' . $image['height'] . '"/>'; $thumb_src = ' <img src="' . $image['thumb_src'] . '" class="image_thumb"
// insert image details - for rogue images if (isset($_POST['insert']) && $_POST['insert'] == 'insert details') { $insert_status = insert_image_details($_POST); if ($insert_status == true) { header('Location: ' . $_SERVER["PHP_SELF"] . '?page_name=images&image_id=' . $insert_status); } else { $error = $insert_status; } } // replace thumbnail if (isset($_POST['replace_thumb'])) { if (isset($_FILES['new_thumb']) && empty($_FILES['new_thumb']['error'])) { $location = WW_ROOT . '/ww_files/images/thumbs/'; $current = $_POST['current_thumb']; $new = $_FILES['new_thumb']; $th_replace_status = replace_file($location, $new, $current); if ($th_replace_status == true) { header('Location: ' . $url); } else { $error = $th_replace_status; } } } // replace image if (isset($_POST['replace_image'])) { if (isset($_FILES['new_image']) && empty($_FILES['new_image']['error'])) { $location = WW_ROOT . '/ww_files/images/'; $current = $_POST['current_image']; $new = $_FILES['new_image']; $image_width = (int) $_POST['image_width']; $replace_status = replace_image($location, $new, $current, $image_width);