Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8860081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:11:54+00:00 2026-06-14T15:11:54+00:00

So, I’m trying to upload xls and xlsx files to my server (NginX on

  • 0

So, I’m trying to upload xls and xlsx files to my server (NginX on a Yii framework), which has a php script to parse the data and add it to the database.

Simple enough.

However, I’m stumbling at the first block; when uploading the file, PHPExcel can’t seem to find the file -and to be honest, I’m not sure it’s there, because I can’t get a solid understanding of where it should be. Below is my code

<code>
<?php
spl_autoload_unregister(array('YiiBase','autoload')); 

/** Include path **/

set_include_path(get_include_path() . PATH_SEPARATOR . '/usr/share/nginx/www/dashboard/protected/extensions/phpexcel/Classes/');


/** PHPExcel_IOFactory */

include 'PHPExcel/IOFactory.php';
spl_autoload_register(array('YiiBase','autoload'));

echo $_FILES . "<br />";

$inputFileName = $_POST;

foreach ($inputFileName as $key => $value) {
    echo "Key: $key; Value: $value<br />\n";
    }
    echo $inputFileName["file"] . "<br />";

echo 'Loading file ',pathinfo($inputFileName["file"],PATHINFO_BASENAME),' using IOFactory to identify the format<br />'; 

//This is where it breaks  
$objPHPExcel = PHPExcel_IOFactory::load($inputFileName["file"]);
</code>

And when it breaks, it hands me this error:

<code>
Could not open Active, Telemetered, Electricity Accounts 17-10-2012.xlsx for reading! File does not exist.
</code>

and this stack trace:

<code>
 /**  
225      * Can the current PHPExcel_Reader_IReader read the file?  
226      *  
227      * @param     string         $pFileName  
228      * @return     boolean  
229      * @throws Exception  
230      */
231     public function canRead($pFilename)  
232     {  
233         // Check if file exists  
234         if (!file_exists($pFilename)) {  
235             throw new Exception("Could not open " . $pFilename . " for reading! File does not exist.");  
236         }  
237 
238         // Check if zip class exists  
239         if (!class_exists('ZipArchive',FALSE)) {  
240             throw new Exception("ZipArchive library is not enabled");  
241         }  
</code>

Now, as I understand it, pathinfo() should have given PHP what it needs to find the file, and that file should be living in php’s temp folder once I hit the upload button (simple html form; I can get the filename from $_POST, so I know it gets that far), but either it’s not actually uploading or it’s getting lost once it’s up.

Any help is much appreciated!

EDIT: html upload form:

<code>
<form action="testFile" method="post">
<label for="file" />
<input type="file" name="file"   />
<br />
<input type="submit">
</form>
</code>

EDIT:

The html upload form was at fault; since I didn’t set the enctype, $_FILES didn’t get populated. Setting the encoding to multipart/form data let me get at the information I needed. Thank you both!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T15:11:56+00:00Added an answer on June 14, 2026 at 3:11 pm

    Since you are using Yii use the CUploadedFile class, call getInstance to get access and information regarding the uploaded files. According to Yii Documentation on CUploadedFile

    CUploadedFile represents the information for an uploaded file.

    Call getInstance to retrieve the instance of an uploaded file, and then use saveAs to save it on the server. You may also query other information about the file, including name, tempName, type, size and error.

    For example:

    $form->model->xlsx = CUploadedFile::getInstance($form->model, 'xlsx');
    //save the file, as an example I am assuming that file is an xlsx
    $file = '/importedfiles/'.uniqid().".xlsx";
    if($model->xlsx->saveAs($file))
    {
    //import PHPExcel if you have not already done so
    Yii::import('sharedLibraries.PHPExcel.PHPExcel',true);
                    
    $inputFileType = PHPExcel_IOFactory::identify($file);
    $objReader = PHPExcel_IOFactory::createReader($inputFileType);
    $objPHPExcel = $objReader->load($file);
    $objWorksheet = $objPHPExcel->getActiveSheet();
    ..........
    }
    else
    {
    //handle the error as file could not be saved
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I want to count how many characters a certain string has in PHP, but
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have an autohotkey script which looks up a word in a bilingual dictionary
I'm trying to select an H1 element which is the second-child in its group
I have an array which has BIG numbers and small numbers in it. I
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to create an if statement in PHP that prevents a single post
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.