Online Manga Viewer Error log problem

Discussion in 'HTML & Website Design' started by zais, Aug 18, 2012.

  1. #1
    Ok so I have a issue with my manga viewer, and I have no idea how to fix it. Maybe you guys can help me. The error log keeps repeating this line right here. The (...) parts are just my website information so I took them out.

    [17-Aug-2012 09:37:17 UTC] PHP Warning: is_dir() [<a href='function.is-dir'>function.is-dir</a>]: open_basedir restriction in effect. File(...) is not within the allowed path(s): (...) in (...) functions.inc.php on line 81

    Here is the function file, please see if you can help

    <?php


    require_once("config.inc.php");




    function omv_encode($text) {
    return str_replace(' ', '_', $text);
    }


    function omv_decode($encoded_text) {
    return str_replace('_', ' ', $encoded_text);
    }


    function omv_get_mangas() {
    $mangas = array();


    $dirname = "mangas/";
    $dir = @opendir($dirname);
    if ($dir) {
    while (($file = @readdir($dir)) !== false) {
    if (is_dir($dirname . $file . '/') && ($file != ".") && ($file != "..")) {
    $mangas[] = $file;
    }
    }
    @closedir($dir);
    }


    sort($mangas);


    return $mangas;
    }


    function omv_get_chapters($manga) {
    global $omv_chapters_sorting;
    $chapters = array();
    $chapters_id = array();


    $dirname = "mangas/$manga/";
    $dir = @opendir($dirname);
    if ($dir) {
    while (($file = @readdir($dir)) !== false) {
    if (is_dir($dirname . $file . '/') && ($file != ".") && ($file != "..")) {
    $chapter = array();
    $chapter["folder"] = $file;
    $pos = strpos($file, '-');
    if ($pos === false) {
    $chapter["number"] = $file;
    } else {
    $chapter["number"] = trim(substr($file, 0, $pos - 1));
    $chapter["title"] = trim(substr($file, $pos + 1));
    }


    $chapters_id[] = $chapter["number"];


    $chapters[] = $chapter;
    }
    }
    @closedir($dir);
    }


    array_multisort($chapters_id, $omv_chapters_sorting, $chapters);


    return $chapters;
    }


    function omv_get_chapter_index($chapters, $chapter_number) {
    $i = 0;
    while (($i < count($chapters)) && ($chapters[$i]["number"] != $chapter_number)) $i++;


    return ($i < count($chapters)) ? $i : -1;
    }


    function omv_get_pages($manga, $chapter) {
    global $omv_img_types;
    $pages = array();


    $dirname = "mangas/$manga/$chapter/";
    $dir = @opendir($dirname);
    if ($dir) {
    while (($file = @readdir($dir)) !== false) {
    if (!is_dir($dirname . $file . '/')) {
    $file_extension = strtolower(substr($file, strrpos($file, ".") + 1));
    if (in_array($file_extension, $omv_img_types)) {
    $pages[] = $file;
    }
    }
    }
    @closedir($dir);
    }


    sort($pages);


    return $pages;
    }


    function omv_get_previous_page($manga_e, $chapter_number_e, $current_page, $previous_chapter) {
    if ($current_page > 1) {
    return $manga_e . '/' . $chapter_number_e . '/' . ($current_page - 1);
    } else if ($previous_chapter) {
    $pages = omv_get_pages(omv_decode($manga_e), $previous_chapter["folder"]);
    return $manga_e . '/' . omv_encode($previous_chapter["number"]) . '/' . count($pages);
    } else {
    return null;
    }
    }


    function omv_get_next_page($manga_e, $chapter_number_e, $current_page, $nb_pages, $next_chapter) {
    if ($current_page < $nb_pages) {
    return $manga_e . '/' . $chapter_number_e . '/' . ($current_page + 1);
    } else if ($next_chapter) {
    return $manga_e . '/' . omv_encode($next_chapter["number"]);
    } else {
    return null;
    }
    }


    function omv_get_image_size($img) {
    global $omv_img_resize, $omv_preferred_width;
    $size = array();


    $imginfo = getimagesize($img);
    $size["width"] = intval($imginfo[0]);
    $size["height"] = intval($imginfo[1]);


    if ($omv_img_resize) {
    if ($size["width"] > $omv_preferred_width) {
    $size["height"] = intval($size["height"] * ($omv_preferred_width / $size["width"]));
    $size["width"] = $omv_preferred_width;
    }
    }


    return $size;
    }


    ?>
     
    zais, Aug 18, 2012 IP
  2. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #2
    Not entirely sure what you're trying to do with this, though some sample filenames and the code that's calling this might help... though it appears PHP does not have read permissions to the directories you're trying to access, making this not so much a code issue, as a server one.

    I will say you're messing around with the directory commands too much -- you seem to want just a list of directories that aren't . or .. -- and that's easy using the function GLOB.

    Your "omv_get_mangas" function for example could be replaced simply with $mangas=glob('/mangas/*',GLOB_ONLYDIR); -- since that does not return self (.) or parent (..) dir links, and it automatically sorts them for you.\

    Likewise the extra array and complex multisort might be better as a usort, and the use of POS could just as easily be done with a limited explode.

    Just to show you what I mean:
    
    function omv_get_mangas() {
    	return glob('mangas/*',GLOB_ONLYDIR);
    }
    
    function omv_chapterSortCall($a,$b) {
    	return strcmp($a['number'],$b['number']);
    }
    
    function omv_get_chapters($manga) {
    	$chapters = array();
    	$chapterList=glob('mangas/'.$manga.'/*',GLOB_ONLYDIR);
    	foreach ($chapterList as $key => $chapterName) {
    		$splitData=explode('-',$chapterName,2);
    		$chapters[]=array(
    			'folder' => $chapterName,
    			'number' => $splitData[0],
    			'title' => isset($splitData[1]) ? $splitData[1] : null
    		);
    	}
    	usort($chapters,'omv_chapterSortCall');
    	return $chapters;
    }
    
    Code (markup):
    On the whole the code feels way more complex than need be, but without knowing what it is this is even trying to accomplish, that's kinda hard to weigh in on.
     
    deathshadow, Aug 18, 2012 IP