【发布时间】:2016-11-29 14:45:31
【问题描述】:
我想使用 php 上传 excel 文件,并想在该 excel 文件中执行一些文件操作。我无法上传文件,如果有人有什么想法请帮忙,在服务器端如何获取文件上传的路径?
$target_dir = '上传/';不适合我。我的文件在 D 中:请帮忙。
PHP 代码:
<?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 代码:
<body>
<form action="" method="post" enctype="multipart/form-data">
<input type="file" name="filepath" id="filepath"/></td><td><input type="submit" name="SubmitButton"/>
</body>
【问题讨论】: