How to upload excel file to php server from input type file

0 votes

I want to upload excel file using to php and wanted to perform some file operation in that excel file. I am not able to upload the file , If any one have some Idea please help , in the server side how to get the path from where the file has been uploaded?

$target_dir = 'uploads/'; is not working for me. and My file is in D: Please help.

PHP CODE:

 <?php    
if(isset($_POST['SubmitButton'])){ //check if form was submitted

$target_dir = 'uploads/';
$target_file = $target_dir . basename($_FILES["filepath"]["name"]);
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);

require_once dirname(__FILE__) . '/Includes/Classes/PHPExcel/IOFactory.php';

$inputFileType = PHPExcel_IOFactory::identify($target_file);

$objReader = PHPExcel_IOFactory::createReader($inputFileType);
$objPHPExcel = $objReader->load($target_file);

$i=2;
$val=array();
$count=0;
for($i=2;$i<34;$i++)
{
$val[$count++]=$objPHPExcel->getActiveSheet()->getCell('C'.$i)->getValue();
}
//echo'<pre>';print_r($val);
}    
?>

HTML CODE:

<body>
<form action="" method="post" enctype="multipart/form-data">
<input type="file"  name="filepath" id="filepath"/></td><td><input type="submit" name="SubmitButton"/>
</body>

Jun 8 in JQuery by Edureka
• 13,640 points
259 views

1 answer to this question.

0 votes
You first need to upload the file before the read line: $target_dir = 'uploads/'; $target_file = $target_dir . basename($_FILES["filepath"]["name"]); $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION); move_uploaded_file($_FILES["filepath"]["tmp_name"], $target_file); // rest of your code
answered Jun 9 by gaurav
• 17,580 points

Related Questions In JQuery

0 votes
1 answer

How to scroll to element from bottom to top with a nice animation using Jquery?

Hello @kartik, Assuming you have a button with ...READ MORE

answered Sep 10, 2020 in JQuery by Niroj
• 82,740 points
2,647 views
0 votes
1 answer

How to set jquery input select all on focus?

Hello @kartik, Try using click instead of focus. It seems to ...READ MORE

answered Nov 24, 2020 in JQuery by Niroj
• 82,740 points
1,613 views
0 votes
1 answer

How to add a “readonly” attribute to an <input>?

Hello, For jQuery <1.9 $('#inputId').attr('readonly', true); ...READ MORE

answered Nov 24, 2020 in JQuery by Niroj
• 82,740 points
353 views
0 votes
1 answer

How to Disabling and enabling a html input button?

Hello @kartik, Using jQuery Disabling a html button $('#Button').attr('disabled','disabled'); Enabling a ...READ MORE

answered Nov 26, 2020 in JQuery by Niroj
• 82,740 points
189 views
0 votes
0 answers

What are the main differences between PHPExcel and PhpSpreadsheet?

In project of PHPOffice there are two projects associated ...READ MORE

Jun 23 in PHP by narikkadan
• 11,280 points
14 views
0 votes
0 answers

PHP import Excel into database (xls & xlsx)

One of the plugins I looked for ...READ MORE

Jul 30 in PHP by Kithuzzz
• 4,480 points
7 views
+1 vote
2 answers

Scp Php files into server using gradle

Tru something like this: plugins { id ...READ MORE

answered Oct 11, 2018 in DevOps & Agile by lina
• 8,220 points
546 views
0 votes
1 answer

How do I create folder under an Amazon S3 bucket through PHP API?

Of Course, it is possible to create ...READ MORE

answered Apr 24, 2018 in AWS by anonymous
9,299 views
0 votes
1 answer

How to turn off Auto Refresh on "Stock Price" Data Type in Excel

How do you stop Excel from automatically ...READ MORE

answered Jun 9 in JQuery by gaurav
• 17,580 points
11 views
0 votes
1 answer

Export DataTable to Excel File

Add Interop References. First we need to ...READ MORE

answered Jun 9 in JQuery by gaurav
• 17,580 points
18 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP