Title: read excel file in plugin
Last modified: October 5, 2017

---

# read excel file in plugin

 *  Resolved [whatwhenwhere](https://wordpress.org/support/users/whatwhenwhere/)
 * (@whatwhenwhere)
 * [8 years, 7 months ago](https://wordpress.org/support/topic/read-excel-file-in-plugin/)
 * I write for my own plugin for read excel file, and place file name is test.xls
   in upload directory and when I readed it I got message [http://xxxxx/wp-content/uploads/test.xls](http://xxxxx/wp-content/uploads/test.xls)
   is not readable.
 * I use PHP spreadsheet reader at [http://coursesweb.net/downloads/phpexcelreader.zip](http://coursesweb.net/downloads/phpexcelreader.zip)
   
   my code
 * `$dir = plugin_dir_path( __DIR__ );
    require_once($dir.’/phpExcelReader/Excel/
   reader.php’); $ex = new Spreadsheet_Excel_Reader(); $data = $ex->read($filename);
 * ps:I used wp 4.8.2, window 7, xampp
    Thk for reading
    -  This topic was modified 8 years, 7 months ago by [whatwhenwhere](https://wordpress.org/support/users/whatwhenwhere/).
    -  This topic was modified 8 years, 7 months ago by [whatwhenwhere](https://wordpress.org/support/users/whatwhenwhere/).
    -  This topic was modified 8 years, 7 months ago by [whatwhenwhere](https://wordpress.org/support/users/whatwhenwhere/).

Viewing 7 replies - 1 through 7 (of 7 total)

 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [8 years, 7 months ago](https://wordpress.org/support/topic/read-excel-file-in-plugin/#post-9558996)
 * 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](https://wordpress.org/support/users/whatwhenwhere/)
 * (@whatwhenwhere)
 * [8 years, 7 months ago](https://wordpress.org/support/topic/read-excel-file-in-plugin/#post-9561112)
 * [@bcworkz](https://wordpress.org/support/users/bcworkz/): I try absoblute
    $url
   = ‘[http://xxx/wp-content/uploads/2017/10/test.xls&#8217](http://xxx/wp-content/uploads/2017/10/test.xls&#8217);;
   but got the same message error
 *  Thread Starter [whatwhenwhere](https://wordpress.org/support/users/whatwhenwhere/)
 * (@whatwhenwhere)
 * [8 years, 7 months ago](https://wordpress.org/support/topic/read-excel-file-in-plugin/#post-9561657)
 * 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.
    -  This reply was modified 8 years, 7 months ago by [whatwhenwhere](https://wordpress.org/support/users/whatwhenwhere/).
    -  This reply was modified 8 years, 7 months ago by [whatwhenwhere](https://wordpress.org/support/users/whatwhenwhere/).
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [8 years, 7 months ago](https://wordpress.org/support/topic/read-excel-file-in-plugin/#post-9562912)
 * 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](https://wordpress.org/support/users/whatwhenwhere/)
 * (@whatwhenwhere)
 * [8 years, 7 months ago](https://wordpress.org/support/topic/read-excel-file-in-plugin/#post-9565718)
 * [@bcworkz](https://wordpress.org/support/users/bcworkz/): sr my english is poor,
   my meaning is my plugin is operation in backend(admin) and not working properly.
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [8 years, 7 months ago](https://wordpress.org/support/topic/read-excel-file-in-plugin/#post-9567518)
 * 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](https://wordpress.org/support/users/whatwhenwhere/)
 * (@whatwhenwhere)
 * [8 years, 4 months ago](https://wordpress.org/support/topic/read-excel-file-in-plugin/#post-9846172)
 * 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 8 years, 4 months ago by [whatwhenwhere](https://wordpress.org/support/users/whatwhenwhere/).

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘read excel file in plugin’ is closed to new replies.

## Tags

 * [Excel](https://wordpress.org/support/topic-tag/excel/)

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 7 replies
 * 2 participants
 * Last reply from: [whatwhenwhere](https://wordpress.org/support/users/whatwhenwhere/)
 * Last activity: [8 years, 4 months ago](https://wordpress.org/support/topic/read-excel-file-in-plugin/#post-9846172)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
