0

I facing a problem regarding the import of an excel file into mysql through php. i have used phptriad as a local server to test my web application(site). The application imports the excel file present on the client side computer. the code works fine when accessed through local server.

recently i have registered a subdomain at orgfree.com. i have uploaded all the application files onto the site. but 'importing excel file' function does not work. it shows 'the file D:\test.xls is not readable' error(test.xls is on my laptop).

what could be the solution to this problem? please help

Here is the code

require_once 'reader.php';
$excelrow=0;$excelcol=0;                    
function parseExcel($excel_file_name_with_path)
{
    global $excelrow,$excelcol;
    $data = new Spreadsheet_Excel_Reader();
    // Set output Encoding.
    $data->setOutputEncoding('CP1251');
    $data->read($excel_file_name_with_path);
    $colname=array('id','name');                    
    for ($i = 1; $i <= $data->sheets[0]['numRows']; $i++)
        {
            for ($j = 1; $j <= $data->sheets[0]['numCols']; $j++)
            {
              $product[$i-1][$j-1]=$data->sheets[0]['cells'][$i][$j];
              $product[$i-1][$colname[$j-1]]=$data->sheets[0]['cells'][$i][$j];
            }
        }
    $excelrow=$i;$excelcol=$j;
    return $product;
}
$data=parseExcel($file);

for($i=0;$i<$excelrow-1;$i++)
{
    for($j=0;$j<$excelcol-1;$j++)
    {
        $fname=ucfirst(strtolower($data[$i][0]));
        $lname=ucfirst(strtolower($data[$i][1]));
        $gender=ucfirst(strtolower($data[$i][2]));
        $phoneno=$data[$i][3];
            $email=strtolower($data[$i][4]);                            
        $occup=ucfirst(strtolower($data[$i][5]));
        $city=ucfirst(strtolower($data[$i][6]));                
    }
        //THEN INSERT INTO DATABASE THROUGH SQL QUERIES                     
}

note: there is only one user to the application i.e., Administrator.

10
  • Do you have the correct file permissions? Commented Oct 31, 2010 at 16:09
  • Well, this question is thorougly unanswerable as long as you don't show some code. For what it's worth though, the "D:\test.xls" sounds like your file upload is accessing the name parameter in the FILES array and not tmp_name Commented Oct 31, 2010 at 16:10
  • sorry but what is 'name' parameter and 'tmp_name' parameter? Commented Oct 31, 2010 at 16:14
  • please note: i have used a excel reader file which i downloaded. Commented Oct 31, 2010 at 16:16
  • @PVB as I said, you will need to show some code to get answers Commented Oct 31, 2010 at 16:16

1 Answer 1

1

Your problem is probably the fact that when running a script on a remote server, you will not have access to your local files any more. This happened to work when the server was running on the local machine, but the remote server has no way of seeing your computer's files.

You would have to add an upload facility. A rudimentary example is outlined in the PHP manual on file uploads.

Alternatively, if you want to use this only for yourself and not as a public service, you could also upload each Excel file to the remote server using FTP, and change the path accordingly to match the new location.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.