Results 1 to 24 of 24

Thread: File Type?

  1. #1

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256

    File Type?

    I can't figure out what's wrong with this:

    PHP Code:
    if ($userfile_type != "image/gif" || $usefile_type != "image/jpeg") {
            echo 
    "Invalid file type!";
    } else {
            echo 
    "It's good!";

    When the conditional should be false, it goes to true anyways.

    However, this will work:

    PHP Code:
    if ($userfile_type != "image/gif") {
            echo 
    "Invalid file type!";
    } else {
            echo 
    "It's good!";

    My evil laugh has a squeak in it.

    kristopherwilson.com

  2. #2
    Fanatic Member Gimlin's Avatar
    Join Date
    Dec 2001
    Location
    Hell
    Posts
    734
    The first on the right one is missing a "r" in "$userfile".

  3. #3
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616

    Re: File Type?

    Your code is incorrect:

    Originally posted by The Hobo
    I can't figure out what's wrong with this:

    PHP Code:
    if ($userfile_type != "image/gif" || $usefile_type != "image/jpeg") {
            echo 
    "Invalid file type!";
    } else {
            echo 
    "It's good!";

    When the conditional should be false, it goes to true anyways.

    However, this will work:

    PHP Code:
    if ($userfile_type != "image/gif") {
            echo 
    "Invalid file type!";
    } else {
            echo 
    "It's good!";


    Change || to && as the file will never be both so it will always run that first statement.

    PHP Code:
    if ($userfile_type != "image/gif" && $usefile_type != "image/jpeg") {
            echo 
    "Invalid file type!";
    } else {
            echo 
    "It's good!";


    -Matt
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

  4. #4
    scoutt
    Guest
    I do hope you know hobo that $userfile_type and $userfile_name is deprecated and you should be using $_FILE[userfile][name]

    but you being a stud and all, you knew that being you slept with php and all.

  5. #5
    Member
    Join Date
    Apr 2002
    Posts
    52
    Originally posted by scoutt
    I do hope you know hobo that $userfile_type and $userfile_name is deprecated and you should be using $_FILE[userfile][name]

    but you being a stud and all, you knew that being you slept with php and all.

    Do I sense sarcasm...?

  6. #6

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by scoutt
    I do hope you know hobo that $userfile_type and $userfile_name is deprecated and you should be using $_FILE[userfile][name]

    but you being a stud and all, you knew that being you slept with php and all.
    oh...you stuck me in the side...

    So, scoutt...I was checking out your site the other day...decided to view the source. You do know the <font> tag is deprecated, right? Checkmate!
    My evil laugh has a squeak in it.

    kristopherwilson.com

  7. #7

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256

    Re: Re: File Type?

    Originally posted by cpradio

    Change || to && as the file will never be both so it will always run that first statement.

    PHP Code:
    if ($userfile_type != "image/gif" && $usefile_type != "image/jpeg") {
            echo 
    "Invalid file type!";
    } else {
            echo 
    "It's good!";

    -Matt
    Sorry, but using the && would mean that it is BOTH gif AND jpeg...

    I want || because if it's NOT gif OR if it's NOT jpeg, then print "Invalid file type!"

    Unless I've totally gone retarded.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  8. #8
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616
    yes you have gone totally retarded.

    Think about it, what if you submit a gif image, then the jpeg statement will be true and thus it will print out the error message, it has to be AND or else no matter what it will print out the statement.

    -Matt
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

  9. #9

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by scoutt
    I do hope you know hobo that $userfile_type and $userfile_name is deprecated and you should be using $_FILE[userfile][name]

    but you being a stud and all, you knew that being you slept with php and all.
    And by the way, I didn't know that. Where could I look up more information on it? Maybe, here: http://www.php.net/manual/en/features.file-upload.php !?

    Thanks, scoutt!
    My evil laugh has a squeak in it.

    kristopherwilson.com

  10. #10

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by cpradio
    yes you have gone totally retarded.

    Think about it, what if you submit a gif image, then the jpeg statement will be true and thus it will print out the error message, it has to be AND or else no matter what it will print out the statement.

    -Matt
    I'm still not following. The user can upload a GIF or a JPEG. I am checking to see if it's not either of them.

    If it's and, it would imply that the uploaded file is both GIF and JPEG. As far as I know that's not possible.

    So please explain it to me like you would to a third grader.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  11. #11
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616
    Okay, here it is in plain english.

    Say you are uploading the file image.gif

    With your code that would mean that
    PHP Code:
    $userfile_type != "image/gif" 
    is false, therefor
    PHP Code:
    $userfile_type != "image/jpeg" 
    is true and thus the error message shows

    And vice versa if the file you are uploading is image.jpg or image.jpeg then
    PHP Code:
    $userfile_type != "image/gif" 
    would be true and thus the error message is shown.

    Therefor you have to make sure that the file being upload is neither gif or jpeg meaning you have to use AND.

    Just try the code and watch it work, I guarentee it.

    -Matt
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

  12. #12

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    See! When you talk to me like I'm 10, it all makes sense. I understand what you mean now. Thanks for your help
    My evil laugh has a squeak in it.

    kristopherwilson.com

  13. #13
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616
    hey no problem.
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

  14. #14

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    PHP Code:
    if ($action == 'submit') {
        if (
    $_FILES['userfile']['size'] > 25000) {
            echo 
    "File Size is too large!";
        } elseif (
    $_FILES['userfile']['type'] != "image/gif" && $_FILES['userfile']['type'] != "image/jpeg") {
            echo 
    "Invalid file type!";
        } elseif (
    file_exists("/home/vbshelf/public_html/tutorials/images/"$_FILES['userfile']['name']) == true) {
            echo 
    "File already exists!";
        } else {
            if(!
    copy($_FILES['userfile']['tmp_name'], "/home/vbshelf/public_html/tutorials/images/"$_FILES['userfile']['name']) {
                echo 
    "Failed to copy...";
                echo 
    "<br>$userfile_name";
            } else {
                echo 
    "Your upload sucessful! The file is saved on the server as ";
                echo 
    "http://www.vbshelf.com/tutorials/images/" $_FILES['userfile']['name'];
            }
        }
    } else {
        echo 
    '<form action="upload.php" ENCTYPE="multipart/form-data" method="post">
        <input type="hidden" name="MAX_FILE_SIZE" value="25000">
        <input type="hidden" name="action" value="submit">
        <b>File Name</b>:<br>
        The file may only be GIF or JPG and is limited to 25 KB in size<br>
        <input type="file" name="userfile"><br><br>
        <input type="submit" value=" Upload File ">'
    ;

    So does this look good? Up to standards and everything (scoutt)?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  15. #15
    scoutt
    Guest
    Originally posted by The Hobo


    oh...you stuck me in the side...

    So, scoutt...I was checking out your site the other day...decided to view the source. You do know the <font> tag is deprecated, right? Checkmate!
    wanna tell me where? I thought I got rid of all of them.

  16. #16

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    I still use them, so I shouldn't gripe...but I saw a few (the only reason I looked was to shoot back at you )

    I actually found very few of them:

    <FONT COLOR="#000080" SIZE="2" FACE="Verdana,Geneva,Georgia,Arial">
    <B>How long have you been programming?</B></FONT>
    In fact, that's it on your index page. Just a few in the poll.

    Edit: Should I remove them from my page as well? Just change it all to CSS?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  17. #17
    scoutt
    Guest
    that is all up to you. I did have a few just to change the size of the font and to change class.

    I didn't look at the files that house the poll. thanks I will get right on it.

    in fact I still use something that is not a 4.01 standard. and the only reason I still have it is because of NS4.xx. but other than that it is 4.01 standardized.

    I only brought that up ($_files) is because I would hate to see you do this script and the the next version of php you have to change it all because userfile_name doesn't work. just looking out for my php comrades

  18. #18
    Frenzied Member blindlizard's Avatar
    Join Date
    Feb 2001
    Location
    Austin, TX - United States of America
    Posts
    1,141
    Originally posted by scoutt
    that is all up to you. I did have a few just to change the size of the font and to change class.

    I didn't look at the files that house the poll. thanks I will get right on it.

    in fact I still use something that is not a 4.01 standard. and the only reason I still have it is because of NS4.xx. but other than that it is 4.01 standardized.

    I only brought that up ($_files) is because I would hate to see you do this script and the the next version of php you have to change it all because userfile_name doesn't work. just looking out for my php comrades
    Any idea why they are changing it?
    I drink to make other people more interesting!
    [vbcode]On Error GoTo Bar[/vbcode]
    http://www.monsterlizard.com

  19. #19
    scoutt
    Guest
    because they turned off register_globals off by default for security reasons.
    when that goes off there are a lot of things that stop working. that is where the super globals comes into play.

    the super globals are easier to use I think.

  20. #20

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Will the same apply to FORM variables?

    Ex: <input name="dog">

    Will PHP still automatically create $dog, or will we need to use $_POST['dog']?

    Also what version will this be taking place in?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  21. #21
    Frenzied Member ae_jester's Avatar
    Join Date
    Jun 2001
    Location
    Kitchener Ontario Canada Earth
    Posts
    1,545
    also i hope your original post wasnt your actual code

    you have

    $userfile_type in the first condition and then
    $usefile_type in the second contition

  22. #22

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by ae_jester
    also i hope your original post wasnt your actual code

    you have

    $userfile_type in the first condition and then
    $usefile_type in the second contition
    This has already been pointed out. It's a simple typo. Please don't lynch me.

    And no, it wasn't in my actual code as I typed that in off the top of my head.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  23. #23
    scoutt
    Guest
    Originally posted by The Hobo
    Will the same apply to FORM variables?

    Ex: <input name="dog">

    Will PHP still automatically create $dog, or will we need to use $_POST['dog']?

    Also what version will this be taking place in?
    you are correct. every variable that is sent through a form or cookie or session will have to be got with a super global. I use $_REQUEST instead of $_POST, easier I think. the version that all this starts in is 4.2.+. Version 4.1.x has problems with sessions and some other bugs so you might want to turn register_globals off on that too. for example, this forum would not operate if the globals were turned off. they are writing a version (v. 3) to run with globals off or on.

  24. #24

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Thanks.
    My evil laugh has a squeak in it.

    kristopherwilson.com

Posting Permissions

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



Click Here to Expand Forum to Full Width