Hey guys..

This is the code of a
string test_func(resource $handle) which is supposed to return the size of
resource as a string.

PHP_FUNCTION(test_func)

*{*
        zval *arg1;
        php_stream_statbuf stat_ssb;
        *char* *input_stream_len_str;
        php_stream *input_stream;

        *if* (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &arg1) ==
FAILURE) *{*
                *return*;
        *}*


        PHP_STREAM_TO_ZVAL(input_stream, &arg1);

        *if* (php_stream_stat(input_stream, &stat_ssb)) *{*
                RETURN_FALSE;
        *}*

        sprintf(input_stream_len_str,"%d",stat_ssb.sb.st_size);
        RETURN_STRING(input_stream_len_str, 1);
                
*}*

I'm testing the above code by using test.php

<?php //test.php
       $fp = $fopen("file.txt","r");
       $str = "samplestr";
       $str = test_func($fp);
       var_dump($str);
?>

but when I hit http://localhost/test.php Instead of showing the string, my
browser is offering *test.php* for download. If I click save, its saving a
zero byte test.php to my disk.

If I comment out the function call to test_func() its showing the var_dump
of $str.

I couldn't understand whats going wrong. Please help.

Reply via email to