1
votes

i am currently using phpexcel library to read my excel file which is to be uploaded by user . but i cannot at this moment :(

i am using this code, i cannot get the file path right at this moment and if some one could tell me , how to over ride existing file and renaming the input file.

  move_uploaded_file($_FILES["file"]["tmp_name"],
  "upload/" . $_FILES["file"]["name"]);
  $test= $_FILES["file"]["name"];
  echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
  require_once('classes/phpexcel.php');
  $objReader = PHPExcel_IOFactory::createReader('Excel2007');
  $objReader->setReadDataOnly(true);
  $objPHPExcel = $objReader->load('upload/'.$test);
  $objWorksheet = $objPHPExcel->setActiveSheetIndex('0') ;

kindly help and thanks in advance

File is being transferred to the desired folder , i cannot open the file with phpexcel

1
Wait, what's the problem? The file won't open, or the file won't save? Are you getting any error messages? Need more details please. - Chris Baker
never assume the move call succeeded. always check if it returns boolean true (success) and only THEN start working with the file. Plus, never use the provided ['name'] - it's user-provided data and can contain path data, letting the upload scribble ANYWHERE on your server that the web process has write permissions to. - Marc B
file is being transferred perfectly , no issue there. issue is when i try $objPHPExcel = $objReader->load('upload/'.$test); this line - Faizan Tanveer

1 Answers

0
votes

I'd sanitize the destination file name on the move_uploaded_file. use something like tempnam() to generate a safe file name