Page 1 of 1

Displaying a selected excel file's content in to a webpage

Posted: Mon Jan 07, 2013 9:29 pm
by nandakishor
I am sorry, If I am asking a basic question..

I am working for a project where I need to give a upload and submit option for client. In that client will browse the local path and selects required "EXCEL" file and if they click to submit, then the content should be displayed in the webpage..
these are few codes I went through, but I thought I am not in the right way..

Code: Select all

<TITLE> PHP File Upload Script </TITLE>
if( isset($_POST['submit1'])) {
// $_FILES is the array auto filled when you upload a file and submit a form.
$userfile_name = $_FILES['file1']['name']; // file name
$userfile_tmp  = $_FILES['file1']['tmp_name']; // actual location
$userfile_size  = $_FILES['file1']['size']; // file size
$userfile_type  = $_FILES['file1']['type']; // mime type of file sent by browser. PHP doesn't check it. 
$userfile_error  = $_FILES['file1']['error']; // any error!. get from here

// Content uploading.
$file_data = '';
if ( !empty($userfile_tmp))
// We encode the data just to make it more database friendly
$file_data = base64_encode(@fread(fopen($userfile_tmp, 'r'), filesize($userfile_tmp) ) );

switch (true)
// Check error if any
case ($userfile_error == UPLOAD_ERR_NO_FILE):
case empty($file_data):
echo 'You must select a document to upload before you can save this page.';
case ($userfile_error == UPLOAD_ERR_INI_SIZE):
case ($userfile_error == UPLOAD_ERR_FORM_SIZE):
echo 'The document you have attempted to upload is too large.';

case ($userfile_error == UPLOAD_ERR_PARTIAL):
echo 'An error occured while trying to recieve the file. Please try again.';


if( !empty($userfile_tmp))
// only MS office and text file is accepted.
if( !(($userfile_type=="application/msword") || ($userfile_type=="text/plain") || ($userfile_type=="application/")) )
{echo 'Your File Type is:'. $userfile_type;
echo '<br>File type must be text(.txt) or msword(.doc).';

echo filesize($userfile_tmp);

<form name="profile" method="POST" action="<?php echo $_SERVER['PHP_SELF'] ?>" target="_self" enctype="multipart/form-data" >

<P align ="center"><input type="hidden" name="MAX_FILE_SIZE" value="1000000">
<input type="file" name="file1" value="AttachFile" device="files" accept="text/*" tabindex=18 >

<input type="submit" name="submit1" value="Submit" />


from the above code I am getting only file size..

This code will displays the content of excel file but it is a hard coded one, but I need client should select that file and content get displayed in the webpage itself...

Code: Select all

error_reporting(E_ALL ^ E_NOTICE);
require_once 'excel_reader2.php';
$data = new Spreadsheet_Excel_Reader("test.xls");
<?php echo $data->dump(true,true); ?>
Thanks in advance...

Re: Displaying a selected excel file's content in to a webpa

Posted: Wed Jan 09, 2013 1:47 am
by nandakishor