uploading file problems

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • lion

    uploading file problems

    I get these errors when uploading images via a web page:
    (the page still uploads the images but reports these errors?)

    Warning: fopen(D:\php\up loadtemp\php1FC 7.tmp) [function.fopen]: failed
    to create stream: No error in
    D:\webspace\me. co.uk\wwwroot\t est\Live.php on line 105

    Warning: Wrong parameter count for filesize() in
    D:\webspace\me. co.uk\wwwroot\t est\Live.php on line 109

    Warning: fread(): supplied argument is not a valid stream resource in
    D:\webspace\me. co.uk\wwwroot\t est\Live.php on line 109

    Warning: Cannot modify header information - headers already sent by
    (output started at D:\webspace\me. co.uk\wwwroot\t est\Live.php:10 5) in
    D:\webspace\me. co.uk\wwwroot\t est\Live.php on line 138

    This is the code at these errors:

    105 = // Open file for binary reading ('rb')
    $tempfile = fopen($uploadfi le0,$uploadfile 1,'rb');

    109 = // Read the entire file into memory using PHP's
    // filesize function to get the file size.
    $filedata = fread($tempfile ,filesize($uplo adfile0,$upload file1));

    138 = header('locatio n: ' . $_SERVER['PHP_SELF']);

    any one help?

    I don't get this problem locally on apache 1.3.26 (win32) running php
    4.2.2 BUT this happens when i use the same file on my live server
    running php 4.3.0 on Windows NT

    cheers Lion
  • Andreas Paasch

    #2
    Re: uploading file problems

    lion wrote:
    [color=blue]
    > I get these errors when uploading images via a web page:
    > (the page still uploads the images but reports these errors?)
    >
    > Warning: fopen(D:\php\up loadtemp\php1FC 7.tmp) [function.fopen]: failed
    > to create stream: No error in
    > D:\webspace\me. co.uk\wwwroot\t est\Live.php on line 105
    >
    > Warning: Wrong parameter count for filesize() in
    > D:\webspace\me. co.uk\wwwroot\t est\Live.php on line 109
    >
    > Warning: fread(): supplied argument is not a valid stream resource in
    > D:\webspace\me. co.uk\wwwroot\t est\Live.php on line 109
    >
    > Warning: Cannot modify header information - headers already sent by
    > (output started at D:\webspace\me. co.uk\wwwroot\t est\Live.php:10 5) in
    > D:\webspace\me. co.uk\wwwroot\t est\Live.php on line 138
    >
    > This is the code at these errors:
    >
    > 105 = // Open file for binary reading ('rb')
    > $tempfile = fopen($uploadfi le0,$uploadfile 1,'rb');
    >
    > 109 = // Read the entire file into memory using PHP's
    > // filesize function to get the file size.
    > $filedata = fread($tempfile ,filesize($uplo adfile0,$upload file1));
    >
    > 138 = header('locatio n: ' . $_SERVER['PHP_SELF']);
    >
    > any one help?
    >
    > I don't get this problem locally on apache 1.3.26 (win32) running php
    > 4.2.2 BUT this happens when i use the same file on my live server
    > running php 4.3.0 on Windows NT
    >
    > cheers Lion[/color]

    I had a similar problem, got it solved by setting open_basedir in php.ini to
    correct value.

    You should go to www.php.net and read the manual on open_basedir for further
    info as I don't have it here in my head ...

    HTH,

    /Andreas
    --
    Registeret Linux user #292411

    Comment

    • Rahul Anand

      #3
      Re: uploading file problems

      adamslionel@hot mail.com (lion) wrote in message news:<1f72d2de. 0312081336.2348 4ace@posting.go ogle.com>...[color=blue]
      > I get these errors when uploading images via a web page:
      > (the page still uploads the images but reports these errors?)
      >
      > Warning: fopen(D:\php\up loadtemp\php1FC 7.tmp) [function.fopen]: failed
      > to create stream: No error in
      > D:\webspace\me. co.uk\wwwroot\t est\Live.php on line 105
      >
      > Warning: Wrong parameter count for filesize() in
      > D:\webspace\me. co.uk\wwwroot\t est\Live.php on line 109
      >
      > Warning: fread(): supplied argument is not a valid stream resource in
      > D:\webspace\me. co.uk\wwwroot\t est\Live.php on line 109
      >
      > Warning: Cannot modify header information - headers already sent by
      > (output started at D:\webspace\me. co.uk\wwwroot\t est\Live.php:10 5) in
      > D:\webspace\me. co.uk\wwwroot\t est\Live.php on line 138
      >
      > This is the code at these errors:
      >
      > 105 = // Open file for binary reading ('rb')
      > $tempfile = fopen($uploadfi le0,$uploadfile 1,'rb');
      >
      > 109 = // Read the entire file into memory using PHP's
      > // filesize function to get the file size.
      > $filedata = fread($tempfile ,filesize($uplo adfile0,$upload file1));
      >
      > 138 = header('locatio n: ' . $_SERVER['PHP_SELF']);
      >
      > any one help?
      >
      > I don't get this problem locally on apache 1.3.26 (win32) running php
      > 4.2.2 BUT this happens when i use the same file on my live server
      > running php 4.3.0 on Windows NT
      >
      > cheers Lion[/color]

      Hi,

      Please check the following:

      LINE 105: fopen() function takes only a single file name argument and
      the mode.
      LINE 109: filesize() function takes only a single argument
      LINE 138: With above two errors fixed this error will also get fixed.

      Following is the correct syntax
      fopen: resource fopen ( string filename, string mode [, int
      use_include_pat h [, resource zcontext]] )

      filesize: int filesize ( string filename )

      -- Rahul

      Comment

      • lion

        #4
        Re: uploading file problems

        cheers guys!

        one thing though regarding Rahul suggestion - I need to upload two
        files (a big pic and its thumbnail) will I not be able to do this at
        once if that is the case?

        I'll give it a go

        I guess I could put it in a loop...?

        cheers
        [color=blue]
        > LINE 105: fopen() function takes only a single file name argument and
        > the mode.
        > LINE 109: filesize() function takes only a single argument
        > LINE 138: With above two errors fixed this error will also get fixed.
        >
        > Following is the correct syntax
        > fopen: resource fopen ( string filename, string mode [, int
        > use_include_pat h [, resource zcontext]] )
        >
        > filesize: int filesize ( string filename )
        >
        > -- Rahul[/color]

        Comment

        • lion

          #5
          Re: uploading file problems

          right, I've tried just passing one file upload to the script but it
          still does'nt work and reports the same errors, does any one know why
          this works fine with php 4.2.2 on apache 1.3.26...? but not on my live
          host which has php 4.3...

          doesnt add up...

          lion

          Comment

          • Rahul Anand

            #6
            Re: uploading file problems

            > cheers guys![color=blue]
            >
            > one thing though regarding Rahul suggestion - I need to upload two
            > files (a big pic and its thumbnail) will I not be able to do this at
            > once if that is the case?
            >
            > I'll give it a go
            >
            > I guess I could put it in a loop...?
            >
            > cheers[/color]

            Hi again,

            Multiple files can be uploaded by running a loop and processing file
            in iteration.

            Following is the an example of caode that can handle multiple files
            upload:

            // Start of code
            <?
            if(!empty($_FIL ES))
            {
            $uploaddir = "../NewsLetterImage s/";
            $errorMessage =
            array(
            1=>"File exceeds the 2 MB limit" ,
            2=>"File exceeds the 2 MB limit",
            3=>"Only partially uploaded.",
            );

            foreach($_FILES['htmlImageFiles ']['name'] as $vk=>$vv)
            {
            if(!empty($vv))
            {
            if(!file_exists ($uploaddir . $vv) &&
            $_FILES['htmlImageFiles ']['error'][$vk] == 0)
            move_uploaded_f ile($_FILES['htmlImageFiles ']['tmp_name'][$vk],
            $uploaddir . $vv);
            else
            {
            $message = $vv;
            if($_FILES['htmlImageFiles ']['error'][$vk] != 0)
            $message .= " (".$errorMessag e[$_FILES['htmlImageFiles ']['error'][$vk]].")
            ";
            else
            $message .= " (File already exists) ";
            $errorFiles[] = $message;
            }
            }
            }
            if(!empty($erro rFiles))
            {
            // Error Uploading files
            $_HEADER_="Erro r Uploading Files";
            $_MESSAGE_="Sor ry! Unable to uplaod following files:-<p>
            ".implode('<br> ',$errorFiles);
            $_MESSAGE_ .= "<p><a href='uploadFor m.html'>Go back to try
            again</a><p>Please note you can not upload duplicate files or files of
            size greater than 2 MB.";
            include_once "errorPage.php" ;
            exit;
            }
            // Success
            header("Locatio n: succesPage.php" );
            exit;
            }
            ?>
            // End of code

            In my HTML form I used this code

            <!-- START HTML CODE -->

            <table>
            <tr>
            <td align="center"> <h3>Upload Newsletter Images</h3></td>
            </tr>
            <tr>
            <td class="normal_s tyle">
            <b>Image File 1</b>
            <input type="file" name="htmlImage Files[]"><p>
            </td>
            </tr>
            <tr>
            <td class="normal_s tyle">
            <b>Image File 2</b>
            <input type="file" name="htmlImage Files[]"><p>
            </td>
            </tr>
            <tr>
            <td class="normal_s tyle">
            <b>Image File 3</b>
            <input type="file" name="htmlImage Files[]"><p>
            </td>
            </tr>
            <tr>
            <td class="normal_s tyle">
            <b>Image File 4</b>
            <input type="file" name="htmlImage Files[]"><p>
            </td>
            </tr>
            </table>

            <!-- END HTML CODE -->


            I guess this will help.

            -- Rahul

            Comment

            • Rahul Anand

              #7
              Re: uploading file problems

              adamslionel@hot mail.com (lion) wrote in message news:<1f72d2de. 0312091332.7982 8e26@posting.go ogle.com>...[color=blue]
              > right, I've tried just passing one file upload to the script but it
              > still does'nt work and reports the same errors, does any one know why
              > this works fine with php 4.2.2 on apache 1.3.26...? but not on my live
              > host which has php 4.3...
              >
              > doesnt add up...
              >
              > lion[/color]

              are you getting the same errors?

              please write your modified code and errors you are getting.

              -- Rahul

              Comment

              • lion

                #8
                Re: uploading file problems

                That was just the ticket - works perfect!

                thankyou very much Rahul

                Lion

                Comment

                Working...