php output file help

wonderd

Board Regular
Joined
Oct 20, 2013
Messages
168
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:

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).

Forum statistics

Threads
1,214,948
Messages
6,122,420
Members
449,083
Latest member
Ava19

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top