SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Dec 2003
    Location
    Ireland
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Problem Reading Files

    I'm trying to create a script to read the contents of a text file submitted in a form into a variable, for use elsewhere. I'd prefer not to have to save the file to the server if at all possible. However, I've wasted a fair whack of this morning trying in vain to accomplish this. I'm at a pretty basic level, so if anyone can ignore my idiocy, and help, it would be much appreciated.

    What I've been fiddling with is as follows:

    PHP Code:

    <?php 

    extract
    ($_REQUEST);
    extract($_FILES);

    ?>

    <html>
    <body>
    <p>

    <?php

    if(isset($news_sql)) {
      echo(
    "hello");
    }

    $file fopen($news_sqlr);
    $test fpassthru($file);

    echo(
    "test");
    echo(
    "$test");

    ?>

    </p>
    </body>
    </html>
    And I get the following error messages:

    Warning: fopen() expects parameter 1 to be string, array given in /home/hsphere/local/home/msweeney/msweeney.k39.kfmcrthy.com/cms/test5.php on line 18

    Warning: fpassthru(): supplied argument is not a valid stream resource in /home/hsphere/local/home/msweeney/msweeney.k39.kfmcrthy.com/cms/test5.php on line 19

    Can anyone can point me in the right direction, or to a tutorial that might help? Thanks in advance.

  2. #2
    Mal Reynolds Mandibal's Avatar
    Join Date
    Aug 2003
    Location
    Columbus
    Posts
    718
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    First the function fopen() expects the name of a file. Apparently according to the warning your passing it an array. the question is what is $news_sql? I'm assuming its from your form but how exactly does your form work. What exactly does extract() do? I can make guesses but its easier if you explain what it does. Thanks.
    Erh

  3. #3
    PHP manual bot bronze trophy Gaheris's Avatar
    Join Date
    Oct 2003
    Location
    Germany
    Posts
    2,195
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    1. See the $_FILES superglobal array, use $news_sql['tmp_name']
    2. fpassthru returns a int and outputs the file directly
    3. You have to move the file with move_uploaded_file first


    What exactly does extract() do?
    See extract, it extracts the content of the array into variables of the current 'namespace'.

  4. #4
    Mal Reynolds Mandibal's Avatar
    Join Date
    Aug 2003
    Location
    Columbus
    Posts
    718
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That answers what the form probably does...didnt notice the $_FILES. You can ignore me and move onto Gaheris' post.
    Erh

  5. #5
    SitePoint Member
    Join Date
    Dec 2003
    Location
    Ireland
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the help. I'm now doing the following,

    PHP Code:
    $file $news_sql['tmp_name'];

    $test readfile($file);

    echo(
    "$test"); 
    And this works, though it outputs a number (5331) at the end of the string when I echo it. Any reason this appears here? Thanks again for the help, much appreciated.

  6. #6
    PHP manual bot bronze trophy Gaheris's Avatar
    Join Date
    Oct 2003
    Location
    Germany
    Posts
    2,195
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do you output something anywhere else, or do you leave PHP mode somewhere? Does it still print that number when you comment out that echo $test line?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •