Support » Developing with WordPress » read excel file in plugin

Viewing 6 replies - 1 through 6 (of 6 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.

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

    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.

    @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.

Viewing 6 replies - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.