Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/276.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在excel工作表中使用路径上传批量图像 index.html Excel上传 Excel上传_Php_Excel - Fatal编程技术网

Php 如何在excel工作表中使用路径上传批量图像 index.html Excel上传 Excel上传

Php 如何在excel工作表中使用路径上传批量图像 index.html Excel上传 Excel上传,php,excel,Php,Excel,upload.php index.html <html> <head> <title>Excel Upload</title> </head> < body > <center><h2>Excel Upload</h2></center> <f

upload.php

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>

  • 当用户上传.csv文件时,读取文件路径,将图像移动到特定目录


有一个很棒的库,名为,您可以使用它获取excel工作表(或CSV文件)中的所有路径。使用此库可以很好地处理CSV文件。这里有一个代码示例:

<?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++;

}

?>
$filepath='/path/to/your/csv.csv';
$phpExcelFileType=PHPExcel_IOFactory::identify($filepath);
$reader=PHPExcel\u IOFactory::createReader($phpExcelFileType);
$objPHPExcel=$reader->load($filepath);//此对象表示整个excel文件
$highestRow=$objPHPExcel->getActiveSheet()->getHighestRow();
//数组以保存所有图像路径
$ImagePath=[];
//循环遍历A列中的所有行
对于($row=1;$row<$highestRow;$row++){
$currentCell=$objPHPExcel->getActiveSheet()->GetCellByColumnRow(0,$row);
$imagePaths[]=$currentCell()->getValue();//这是指向所需图像的路径
}
//可以根据需要处理$imagePaths中的路径

因为您有图像路径,所以不需要使用tmp_名称或名称变量,您可以使用如下命令:

$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


复制($file,“$location/$file_name”)

但我需要移动图像文件夹@tobias fIt中的原始源代码(C:\Users\Infizoom 3\Pictures\1.PNG),因为您不需要手动将CSV文件的内容拆分为行、单元格等。它不仅支持使用CSV,还支持使用xls,xslx和其他一些文件类型。我阅读了excel数据,但它们可能会将图像移动到一个特定的目录@tobias FFO,或者移动您可以使用的文件,如问题中所述。如果您只想在其他地方创建文件副本,但将原始文件保留在您可以使用的位置。例如,我在文本字段中输入特定图像路径,图像将粘贴到我自己的位置或某个文件夹(图像),我运行此代码仅显示图像名称无法移动目录,先生。echo$file\u name=pathinfo($file,pathinfo\u BASENAME);输出:1.PNGAs您可以看到,我们使用该代码作为文件名。并将$file移动到给定位置。只需检查位置路径和csv中的给定路径是否正确。。并检查移动位置$location=“images”的权限$file=“d:/images/1.png”;移动上传的文件($file,“$location”);那么这里有什么问题?
$file = $filesop[0];
$file_name = pathinfo($file,PATHINFO_BASENAME);
move_uploaded_file($file,"$location/$file_name");