Viewing 7 replies - 1 through 7 (of 7 total)
  • Moderator bcworkz

    (@bcworkz)

    That error is thrown when either is_readable() returns false or file_get_contents() fails to return anything. Why one of these occurs is anyone’s guess.

    My guess: are you sure an URL is called for? Try passing an absolute server path to the file. On Windows machines I believe absolute paths begin with a drive designation.

    Thread Starter whatwhenwhere

    (@whatwhenwhere)

    @bcworkz: I try absoblute
    $url = ‘https://xxx/wp-content/uploads/2017/10/test.xls’;
    but got the same message error

    Thread Starter whatwhenwhere

    (@whatwhenwhere)

    My plugin is working in backend, and I think problem about permission or secure when read file, if I read file excel on hardisk it’s ok or read file csv is ok.

    Moderator bcworkz

    (@bcworkz)

    If it’s working in backend, I can’t imagine why it would not work front end. By absolute path, I mean something without “http”, as in C:\wampp\htdocs/wp/wp-content/uploads/2017/10/test.xls or whatever is correct for your installation. Local PHP file functions often require server paths, not URLs.

    WP runs as a different user than yourself or your WP login when accessing files. It’s defined in httpd.conf, I believe this file is in your wampp folder under /apache/conf/. What ever that user is, be sure the target file allows read access for this user.

    Thread Starter whatwhenwhere

    (@whatwhenwhere)

    @bcworkz: sr my english is poor, my meaning is my plugin is operation in backend(admin) and not working properly.

    Moderator bcworkz

    (@bcworkz)

    OK, no problem, it does not change my answer, only lessens the mystery. It’s almost certainly either path vs. URL issue or user permissions. file_get_contents() does not need a path, URLs are fine. is_readable() does require a path. It results in an error when passed a valid, accessible URL. Even if it did accept URLs, or you did pass a valid path, it will still cause the error you are seeing if the system user that PHP and WP is running under does not have the proper file permission.

    Find out what that user is from the httpd.conf file I mentioned previously, then be sure that user can read the file using the normal Windows file security/permission dialog. Search the file for User occurring at the beginning of a line, what ever is after is the user that needs permission.

    Thread Starter whatwhenwhere

    (@whatwhenwhere)

    I find out that I must read file excel like this code:

    $filecontent = file_get_contents($url);
    file_put_contents($tmpfname, $filecontent);
    $excelReader = PHPExcel_IOFactory::createReaderForFile($tmpfname);
    
    

    with $url is address of file to upload and $tmpfname is hold temp data. Tks

    • This reply was modified 6 years, 10 months ago by whatwhenwhere.
Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘read excel file in plugin’ is closed to new replies.