php中excel文件的上传
我正在用php做一个项目,试图将excel文件上传到服务器上,但每次都失败了。我的代码文件如下:下面给出的newupload.php文件中的所有函数模块都正常工作,但move_upload_file函数不工作,文件也没有移动到目标。请检查我的代码并帮助我php中excel文件的上传,php,excel,file,uploading,Php,Excel,File,Uploading,我正在用php做一个项目,试图将excel文件上传到服务器上,但每次都失败了。我的代码文件如下:下面给出的newupload.php文件中的所有函数模块都正常工作,但move_upload_file函数不工作,文件也没有移动到目标。请检查我的代码并帮助我 //this is first page //index.php <!DOCTYPE html> <html> <body> <
//this is first page
//index.php
<!DOCTYPE html>
<html>
<body>
<form action="newupload.php" method="post" enctype="multipart/form-data">
Select image to upload:
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="submit" value="Upload Image" name="submit">
</form>
</body>
</html>
//second page
//newupload.php
<?php
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);//destination
$uploadOk = 1;
$FileType = pathinfo($target_file,PATHINFO_EXTENSION);//returns extension of file
// Check if image file is a actual image or fake image
if(isset($_POST["submit"])) {
$check = filesize($_FILES["fileToUpload"]["tmp_name"]);
}
// Check if file already exists
if (file_exists($target_file)) {
echo "Sorry, file already exists.";
$uploadOk = 0;
}
// Check file size
if ($_FILES["fileToUpload"]["size"] > 500000) {
echo "Sorry, your file is too large.";
$uploadOk = 0;
}
//checks whether file is excel or not
if($FileType != "xlsx" ) {
echo "Sorry, Excel files are allowed.";
$uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";// this error arising in my program
}
}
?>
//这是第一页
//index.php
选择要上载的图像:
//第二页
//newupload.php
//请帮助我,提前谢谢您可以使用PHPeXCEL类 代码是
require_once 'PHPExcel/IOFactory.php';
$objPHPExcel = PHPExcel_IOFactory::load("MyExcel.xlsx");
foreach ($objPHPExcel->getWorksheetIterator() as $worksheet) {
$worksheetTitle = $worksheet->getTitle();
$highestRow = $worksheet->getHighestRow(); // e.g. 10
$highestColumn = $worksheet->getHighestColumn(); // e.g 'F'
$highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);
$nrColumns = ord($highestColumn) - 64;
echo "<br>The worksheet ".$worksheetTitle." has ";
echo $nrColumns . ' columns (A-' . $highestColumn . ') ';
echo ' and ' . $highestRow . ' row.';
echo '<br>Data: <table border="1"><tr>';
for ($row = 1; $row <= $highestRow; ++ $row) {
echo '<tr>';
for ($col = 0; $col < $highestColumnIndex; ++ $col) {
$cell = $worksheet->getCellByColumnAndRow($col, $row);
$val = $cell->getValue();
$dataType = PHPExcel_Cell_DataType::dataTypeForValue($val);
echo '<td>' . $val . '<br>(Typ ' . $dataType . ')</td>';
}
echo '</tr>';
}
echo '</table>';
}
require_once'PHPExcel/IOFactory.php';
$objPHPExcel=PHPExcel_IOFactory::load(“MyExcel.xlsx”);
foreach($objPHPExcel->getWorksheetIterator()作为$worksheet){
$worksheetTitle=$worksheet->getTitle();
$highestRow=$worksheet->getHighestRow();//例如10
$highestColumn=$worksheet->getHighestColumn();//例如'F'
$highestColumnIndex=PHPExcel_单元::columnIndexFromString($highestColumn);
$nrColumns=ord($highestColumns)-64;
回显“
工作表“$WORKSHEETITLE.”已;
回显$nR列。“列(A-”.$highestColumn.”);
echo'和'$highestRow.'行';
回显'
数据:';
对于($row=1;$row getCellByColumnRow($col,$row);
$val=$cell->getValue();
$dataType=phpexcell\u Cell\u dataType::dataTypeForValue($val);
回显“.$val.”
(典型“$dataType.”);
}
回声';
}
回声';
}
请尝试打印目标完整路径。此外,请尝试授予上载文件夹的权限。更新:@Programming Student我刚刚检查了该程序是否能正确处理小文件,而不能处理大文件。我要上载的文件大约为8MB,这就是为什么它不能工作,而小文件只有5kb,或者上载成功虽然我在index.php中设置了大小限制,但请参考