I am working with PHPExcel and I keep on getting this error:
The file PHPExcel_Shared_String.php is missing in the includes folder.
It is not showing up as a fatel error or anything like that. It is just printing out on the screen. I am using PHPExcel Version 1.8.0.
mypage.php
include('../../../assets/phpexcel/Classes/PHPExcel/IOFactory.php');
$allowedExts = array("xlsx");
$temp = explode(".", $_FILES["file"]["name"]);
$extension = end($temp);
if (($_FILES["file"]["size"] < 4194304) && in_array($extension, $allowedExts)){
if ($_FILES["file"]["error"] > 0){
echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
}
move_uploaded_file($_FILES["file"]["tmp_name"], "./Upload/" . $_FILES["file"]["name"]);
$filename = $_FILES["file"]["name"];
$b = "INSERT INTO uploaded VALUES ('', '".$filename."', NOW(), '".$session->username."')";
$b1 = $minidb->prepare($b);
$b1->execute();
//Begin Database input
// Include our library for reading Excel files
include('../../../assets/phpexcel/Classes/PHPExcel/IOFactory.php');
$file = "..//Upload/".$filename;
// Let's try to read the data
try {
$php_excel = PHPExcel_IOFactory::load($file);
}
catch(Exception $e) {
die('Error loading file "'.pathinfo($file, PATHINFO_BASENAME).'": '.$e->getMessage());
}
$sheet_data = $php_excel->getActiveSheet()->toArray(null,true,true,true);
// Shift our first result, as that is our column data
$columns = array_shift($sheet_data);
// Map our column keys
$column_map = array();
foreach ($columns as $key => $column) {
$column_map[$column] = $key;
}
// Go through our entire sheet and put in our data array to get ready for MySQL import
$data = array();
foreach($sheet_data as $sheet) {
// Only add if our source is HCC
if(!empty($sheet[$column_map['Serial']])) {
//Setting the script for checking Case and T
$serial = $sheet[$column_map['Serial']];
$crown = $sheet[$column_map['crown']];
//Changing all lowercase letters to Uppercase.
$userial = strtoupper($serial);
$ucrown = strtoupper($crown);
//Checking for "T" infront of Serial and Crown
$str_pos = strpos ($userial, 'T');
if($str_pos !== false && $str_pos === 0){
$gserial = $userial;
}else{
$gserial = "T".$userial;
}
$str_pos2 = strpos ($ucrown, 'T');
if($str_pos2 !== false && $str_pos2 === 0){
$gcrown = $ucrown;
}else{
$gcrown = "T".$ucrown;
}
$data[] = array(
'serial' => $gserial,
'crown' => $gcrown,
'description' => $sheet[$column_map['Description']],
'size' => $sheet[$column_map['Size']],
'load_wk' => $sheet[$column_map['wk']],
'bitdate' => $sheet[$column_map['date']],
'partnumber' => $sheet[$column_map['Part number']],
'stockpoint' => $sheet[$column_map['STOCKPOINT']],
'source' => $sheet[$column_map['Source']],
);
}
else{ echo '<h1>OOPS</h1>';}
}
// Go through each order and create batches of 100 inserts. This is better than doing a query for every
// single order, and should keep it running efficiently.
$sql_batch = array();
for($i = 0; $i < count($data); $i++) {
// Add our insert line for every 100
if($i % 100 == 0) {
$sql_batch[floor($i / 100)] = "INSERT IGNORE INTO bits (`" .
implode("`,`", array_keys($data[0])) . "`) VALUES";
}
$sql_batch[floor($i / 100)] .= " ('" .
implode("','", array_values($data[$i])) . "'),";
}
// Do our queries
foreach($sql_batch as $sql) {
// Trim off any final commas
$sql = trim($sql, ",");
// Execute our query
$sql1 = $minidb->prepare($sql);
$sql1->execute();
}
echo "<br>Import Complete.";
//echo "<meta http-equiv=refresh content=2;URL=.>";
}
else{
echo "Invalid file. Please Wait.";
echo "<meta http-equiv=refresh content=1;URL=.>";
/*echo "<script type='text/javascript'>alert('Please Check your File');</script>";*/
}
IOFactory.php
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
/**
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/');
require(PHPEXCEL_ROOT . 'Autoloader.php');
}
Autoloader.php
class PHPExcel_Autoloader
{
/**
* Register the Autoloader with SPL
*
*/
public static function Register() {
if (function_exists('__autoload')) {
// Register any existing autoloader function with SPL, so we don't get any clashes
spl_autoload_register('__autoload');
}
// Register ourselves with SPL
return spl_autoload_register(array('PHPExcel_Autoloader', 'Load'));
} //function Register();
PHPExcel_Shared_String.php
located? Provide the path. Have you tried definingPHPEXCEL_ROOT
? Looks like if you do not define it the default location would be whereverIOFactory.php
is located. What path is theAutoloader.php
file located at? — Brian WozeniakPHPExcel_Shared_String.php
is not a file and never has been. Even in the default zip file from the PHPExcel website. TheAutoloader.php
is located in the same folder asIOFactory.php
. — demonmaestroPHPExcel_Shared_String
orShared_String
? — Brian Wozeniakmypage.php
? The error occurs when you call that page correct? — Brian Wozeniak