Hello, I have a php file I run with command prompt that checks images paths in column B against the actual image in a folder on my computer. If the image does not exist then an output.txt file gets created with the excel row number of the images that do not exist separated by comma ex: 43, 56, 89. My question is how do I change the code to output the value in column A of the row instead of the row number? But not separated by comma but in vertical list format? I am not sure if this belongs in this forum/section.
Code:
function is_valid_image($path)
{
$full_path = realpath(dirname(__FILE__)).dirname($path)."/".basename($path);
if ((substr(PHP_OS, 0, 3)) == "WIN")
{
$full_path = str_replace("/", "\\", $full_path);
}
return (file_exists($full_path));
}
$csv_file = "shagfinal12.csv";
$fp = fopen($csv_file, "r");
$header_row = true;
$row_number = 1;
$invalid_rows = "";
while($row = fgetcsv($fp))
{
if ($header_row)
{
$header_row = FALSE;
}
else
{
$column_A = $row["1"];
if(
!is_valid_image($column_A)
)
{
$invalid_rows .= ", " . $row_number;
}
}
$row_number++;
}
fclose($fp);
if ($invalid_rows != "")
{
echo "Invalid Path Rows: " . substr($invalid_rows, 2);
$fp = fopen("output.txt", "w");
fputs($fp, "Invalid Path Rows: " . substr($invalid_rows, 2));
fclose($fp);
}
Last edited: