SitePoint Sponsor

User Tag List

Results 1 to 12 of 12
  1. #1
    SitePoint Addict rwar's Avatar
    Join Date
    Sep 2001
    Location
    PF / RS / BR
    Posts
    207
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    warnings (bléééé)...

    What's wrong with this code? Someone knows what happens here?

    Warnings:

    Warning: Supplied argument is not a valid File-Handle resource in c:\apache\htdocs\scripts\balhiweb.php on line 33

    Warning: Supplied argument is not a valid File-Handle resource in c:\apache\htdocs\scripts\balhiweb.php on line 36

    My server is on another machine (same LAN). The user must choose a file and the server should show it (this part is not here). T warnings are in lines:

    $file_contents = fread( $filename, filesize( $uploadfilechuva ));

    and

    fclose( $filename );

    PHP Code:
    <HTML>
    <HEAD>
        <TITLE>BalHiWEB 0.1 :: Mais um produto com a qualidade Embrajara!</TITLE>
    </HEAD>
    <BODY>

    <?php
        
    if( $submit )
        {
            if ((
    $filename fopen$uploadfilechuva"r" ) == FALSE ))
            {
                print( 
    "Erro ao abrir arquivo!" );
                exit();
            }

            
    $file_contents fread$filenamefilesize$uploadfilechuva ));
            
    fclose$filename );
    ?>

    <FORM ACTION="<?php echo($PHP_SELF) ; ?>"
            METHOD=POST ENCTYPE="multipart/form-data">

            <P>Selecione o arquivo de chuvas:<BR>
            <INPUT TYPE=FILE NAME="uploadfilechuva">
            <INPUT TYPE=SUBMIT NAME="submit" VALUE="submeter"></P>
            <INPUT TYPE=HIDDEN NAME=MAX_FILE_SIZE VALUE=1048576>
    </FORM>

    </BODY>
    </HTML>
    Thanks for any help.
    php? mysql? apache? That's it.

  2. #2
    SitePoint Enthusiast
    Join Date
    Oct 2001
    Location
    London
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok ,

    First close your if($submit) statement:
    PHP Code:
                                  <?php
                                      
    if( $submit )
                                      {
                                          if ((
    $filename fopen$uploadfilechuva"r" ) == FALSE ))
                                          {
                                              print( 
    "Erro ao abrir arquivo!" );
                                              exit();
                                          }

                                          
    $file_contents fread$filenamefilesize$uploadfilechuva ));
                                          
    fclose$filename );
                                   }    
                                  
    ?>
    Then let us know what happened.

    Espero que tenha ajudado nosso amigo Brasuca!!!
    -- | StEaLThEn |--

  3. #3
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry thats not gonna fix the warnings, the warnings are from the fopen().

    This is not the correct way to get a file uploaded through the browser. You should use copy() instead.

    http://www.php.net/copy
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  4. #4
    SitePoint Addict rwar's Avatar
    Join Date
    Sep 2001
    Location
    PF / RS / BR
    Posts
    207
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for help, stealthen.

    I missed to put a } in the end of the code. It's there. I changed a line of the code. It was a parenthesis in a wrong place.

    PHP Code:
    if (($descriptor fopen$filename"r" )) == FALSE 
    Now I have just one warning:

    Warning: 1 is not a valid File-Handle resource in c:\apache\htdocs\scripts\balhiweb.php on line 36

    I really don't know the '1' is from. A php code?

    PHP Code:
    $file_contents fread$descriptorfilesize$filename )); 
    Is a parenthesis missing?


    OFF-TOPIC: Where are you from, stealthen? Brasil, I suppose... Which part...
    php? mysql? apache? That's it.

  5. #5
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello? Are you listening. If you are trying to upload a file from the browser YOU ARE GOING ABOUT IT THE WRONG WAY. See my post above.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  6. #6
    SitePoint Enthusiast
    Join Date
    Oct 2001
    Location
    London
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well It seems like freddydoesphp knows already what is wrong. So try to use copy()



    Off-Topic -> rwar send me an e-mail I got go off line now.
    -- | StEaLThEn |--

  7. #7
    SitePoint Addict rwar's Avatar
    Join Date
    Sep 2001
    Location
    PF / RS / BR
    Posts
    207
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by freddydoesphp
    Hello? Are you listening. If you are trying to upload a file from the browser YOU ARE GOING ABOUT IT THE WRONG WAY. See my post above.
    Take it easy, man. I was just posting the reply (see h:m:s).

    Thanks, freddydoesphp. I'll try that.
    php? mysql? apache? That's it.

  8. #8
    SitePoint Addict rwar's Avatar
    Join Date
    Sep 2001
    Location
    PF / RS / BR
    Posts
    207
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by freddydoesphp
    Sorry thats not gonna fix the warnings, the warnings are from the fopen().

    This is not the correct way to get a file uploaded through the browser. You should use copy() instead.

    http://www.php.net/copy
    Could you give an example on how a <INPUT TYPE=FILE> work with copy?

    Thanks since now.
    php? mysql? apache? That's it.

  9. #9
    SitePoint Wizard Defender1's Avatar
    Join Date
    Apr 2001
    Location
    My Computer
    Posts
    2,808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you need to use copy() on the uploaded file to copy it to your webserver (as php stores and uploaded file as a temp file that isn't usable yet until you use copy) before you can use the file functions on it.
    read about it at the link freddy posted above.

    though i'd recommend renaming the file as there's a pretty good chance of getting duplicate filenames.
    Defender's Designs
    I'm Getting Married!

    Not-so-patiently awaiting Harry Potter Book 7 *sigh*

  10. #10
    SitePoint Addict rwar's Avatar
    Join Date
    Sep 2001
    Location
    PF / RS / BR
    Posts
    207
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Could you (anyone) write an example? Or write where I can look for one?

    I really didn't understand how it works.

    Thanks.
    php? mysql? apache? That's it.

  11. #11
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  12. #12
    SitePoint Wizard Defender1's Avatar
    Join Date
    Apr 2001
    Location
    My Computer
    Posts
    2,808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <?
    $ext 
    ".jpg"// this is where you put the file extension.
    $path_to "/path/to/store/file".$uploadfilechuva;
    if(
    copy($uploadfilechuva$path_to.'$ext'))
    {
      echo 
    "Hey! It worked!";
    }
    else
    {
      echo 
    "Aw man! It didn't work!";
    }
    ?>
    Defender's Designs
    I'm Getting Married!

    Not-so-patiently awaiting Harry Potter Book 7 *sigh*


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
  •