index.html
<html>
<head>
<title>Excel Upload</title>
</head>
< body >
<center><h2>Excel Upload</h2></center>
<form action = "upload.php" method = "POST" enctype = "multipart/form-data" >
<input type="file" name="file"/> < input type = "submit" value = "Upload" >
< /form>
</body >
< /html>
upload.php的
<?php
$name = $_FILES['file']['name'];
$file = $_FILES['file']['tmp_name'];
$handle = fopen($file, "r");
$c = 0;
$location ="images"
while(($filesop = fgetcsv($handle, 1000, ",")) !== false)
{
$file = $filesop[0];
$file_name = $file[0]['name'];
$file_tmp_name = $file[0]['tmp_name'];
move_uploaded_file($file_tmp_name,"$location/$file_name");
$c++;
}
?>
答案 0 :(得分:0)
有一个名为PHPExcel的精彩库,您可以使用它来获取Excel工作表(或CSV文件)中的所有路径。您可以很好地使用此库处理CSV文件。这里有一个代码示例:
$filepath = '/path/to/your/csv.csv';
$phpExcelFileType = PHPExcel_IOFactory::identify($filepath);
$reader = PHPExcel_IOFactory::createReader($phpExcelFileType);
$objPHPExcel = $reader->load($filepath); // This object represents your whole excel file
$highestRow = $objPHPExcel->getActiveSheet()->getHighestRow();
// Array to hold all of your image paths
$imagePaths = [];
// Loop through all rows in column A
for ($row = 1; $row < $highestRow; $row++){
$currentCell = $objPHPExcel->getActiveSheet()->getCellByColumnAndRow(0, $row);
$imagePaths[] = $currentCell()->getValue(); // this is the path to the image you want
}
// Do with the paths in $imagePaths whatever you want
答案 1 :(得分:0)
由于您有图像路径,因此您不需要使用tmp_name或name变量,而是可以使用:
$file = $filesop[0];
$file_name = pathinfo($file,PATHINFO_BASENAME);
move_uploaded_file($file,"$location/$file_name");
或
拷贝($文件,&#34; $位置/ $ FILE_NAME&#34);