Dateien nach "includes" hochladen
This commit is contained in:
44
includes/upload.php
Normal file
44
includes/upload.php
Normal file
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
require_once 'PHPExcel/Classes/PHPExcel/IOFactory.php';
|
||||
|
||||
if(isset($_POST["submit"])) {
|
||||
$target_dir = "uploads/";
|
||||
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
|
||||
$uploadOk = 1;
|
||||
$fileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
|
||||
|
||||
if ($fileType != "xlsx" && $fileType != "xls") {
|
||||
echo "Sorry, only XLSX and XLS files are allowed.";
|
||||
$uploadOk = 0;
|
||||
}
|
||||
|
||||
if ($uploadOk == 0) {
|
||||
echo "Sorry, your file was not uploaded.";
|
||||
} else {
|
||||
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
|
||||
$objPHPExcel = PHPExcel_IOFactory::load($target_file);
|
||||
$worksheet = $objPHPExcel->getActiveSheet();
|
||||
|
||||
foreach ($worksheet->getRowIterator() as $row) {
|
||||
$cellIterator = $row->getCellIterator();
|
||||
$cellIterator->setIterateOnlyExistingCells(FALSE);
|
||||
|
||||
$data = [];
|
||||
foreach ($cellIterator as $cell) {
|
||||
$data[] = $cell->getValue();
|
||||
}
|
||||
|
||||
// Verarbeiten Sie die Daten hier und fügen Sie die Artikel hinzu
|
||||
// Beispiel: Fügen Sie die Artikel zur Datenbank hinzu
|
||||
// $manufacturer = $data[1];
|
||||
// $article_number = $data[2];
|
||||
// ...
|
||||
|
||||
echo "Article added: " . implode(", ", $data) . "<br>";
|
||||
}
|
||||
} else {
|
||||
echo "Sorry, there was an error uploading your file.";
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
Reference in New Issue
Block a user