ID:               25808
 Updated by:       [EMAIL PROTECTED]
 Reported By:      david dot nicholls at camden dot gov dot uk
 Status:           Feedback
 Bug Type:         Output Control
 Operating System: Windows 2000
 PHP Version:      4.3.3
 New Comment:

Just thought that it could be that filesize() is returning
-1 for the csv file; -1 + 1 == 0, which means that the fgetcsv()
function is returning no data at all, because you
have asked it for none.

Check the permissions on the file, and check the return value.  You
probably don't need the filesize() call at all; just use a reasonable
line length (1024 seems ok to me).



Previous Comments:
------------------------------------------------------------------------

[2003-10-09 12:45:09] [EMAIL PROTECTED]

My theory:

Your command prompt runs under your credentials, and you
have permission to access the network share.

IUSR_<machinename>, the user under which IIS is running,
does not have permissions to access the share.

However, I would expect to see a warning in that case.

------------------------------------------------------------------------

[2003-10-09 12:36:50] david dot nicholls at camden dot gov dot uk

Description:
------------
Data sourced from a CSV file does not echo when a script is invoked via
web browser from IIS 5 but does output when invoked from a cmd via
php.exe.

A simple change of commenting out the line

$csv = get_csv ($csvname);

and uncommenting

// $csv = array ($line,$line,$line);

produces output in the browser and the console as expected

I have checked the CSV file and the data only contains alphanumeric
characters.


Reproduce code:
---------------
<?php

error_reporting(E_ALL);  
echo "Read CSV and Output result<P>";
/*** CSV INPUT ***/
$csvname = '\\\\camden-pdc\\logs$\\logon.csv';

echo "Loading CSV from $csvname<P>";
$csv = get_csv ($csvname);

$line = array(1,"a",3,4,"b",6,7,8,9);
// $csv = array ($line,$line,$line);

echo "Got CSV Printing CSV<P>";


foreach ($csv as $field)
        {
        $strecho = $field[2]."\t\t".$field[5]."<P>\n\r";        echo
addslashes($strecho);           
        }



function get_csv($filename, $delim=',')
{
    $row = 0;
    $dump = array();
    echo "get_csv function<P>";
    $f = fopen ($filename,"r");
    $size = filesize($filename)+1;
    while ($data = fgetcsv($f, $size, $delim)) {
        $dump[$row] = $data;
        $row++;
    }
    fclose ($f);
    
    return $dump;
}
 
?>

Expected result:
----------------
Console Sample

C:\Inetpub\wwwroot>php av.php
Content-type: text/html
X-Powered-By: PHP/4.3.3

Read CSV and Output result<P>Loading CSV from
\\camden-pdc\logs$\logon.csv<P>get
_csv function<P>Got CSV Printing CSV<P>X039482          ENVIRONMENT<P>
X034800         HOUSING<P>
W024792         LEISURE<P>
X030990         ENVIRONMENT<P>
X036399         ITD<P>
X041971         ENVIRONMENT<P>
X033233         ENVIRONMENT<P>
X031711         ENVIRONMENT<P>
X036189         ENVIRONMENT<P>
X047548         HOUSING<P>
X035445         ENVIRONMENT<P>
X039397         HOUSING<P>
X033244         ENVIRONMENT<P>
X026376         ENVIRONMENT<P>

Actual result:
--------------
HTML Output

1 Read CSV and Output result<P>Loading CSV from
\\camden-pdc\logs$\logon.csv<P>get_csv function<P>Got CSV Printing
CSV<P>


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=25808&edit=1

Reply via email to