Example #1
0
function wr2x_from_url_to_system($url)
{
    $img_pathinfo = wr2x_get_pathinfo_from_image_src($url);
    $filepath = trailingslashit(wr2x_get_wordpress_root()) . $img_pathinfo;
    if (file_exists($filepath)) {
        return $filepath;
    }
    $filepath = trailingslashit(wr2x_get_upload_root()) . $img_pathinfo;
    if (file_exists($filepath)) {
        return $filepath;
    }
    return null;
}
Example #2
0
function wr2x_check_get_ajax_uploaded_file()
{
    if (!current_user_can('upload_files')) {
        echo json_encode(array('success' => false, 'message' => __("You do not have permission to upload files.", 'wp-retina-2x')));
        die;
    }
    $data = $_POST['data'];
    // Create the file as a TMP
    if (is_writable(sys_get_temp_dir())) {
        $tmpfname = tempnam(sys_get_temp_dir(), "wpx_");
    } else {
        if (is_writable(wr2x_get_upload_root())) {
            if (!file_exists(trailingslashit(wr2x_get_upload_root()) . "wr2x-tmp")) {
                mkdir(trailingslashit(wr2x_get_upload_root()) . "wr2x-tmp");
            }
            $tmpfname = tempnam(trailingslashit(wr2x_get_upload_root()) . "wr2x-tmp", "wpx_");
        }
    }
    if ($tmpfname == null || $tmpfname == FALSE) {
        $tmpdir = get_temp_dir();
        error_log("Retina: The temporary directory could not be created.");
        echo json_encode(array('success' => false, 'message' => __("The temporary directory could not be created.", 'wp-retina-2x')));
        die;
    }
    $handle = fopen($tmpfname, "w");
    fwrite($handle, base64_decode($data));
    fclose($handle);
    chmod($tmpfname, 0664);
    // Check if it is an image
    $file_info = getimagesize($tmpfname);
    if (empty($file_info)) {
        unlink($tmpfname);
        echo json_encode(array('success' => false, 'message' => __("The file is not an image or the upload went wrong.", 'wp-retina-2x')));
        die;
    }
    $filedata = wp_check_filetype_and_ext($tmpfname, $_POST['filename']);
    if ($filedata["ext"] == "") {
        unlink($current_file);
        echo json_encode(array('success' => false, 'message' => __("You cannot use this file (wrong extension? wrong type?).", 'wp-retina-2x')));
        die;
    }
    return $tmpfname;
}