|
-
May 25th, 2002, 02:22 PM
#1
Thread Starter
Stuck in the 80s
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!";
}
-
May 25th, 2002, 03:44 PM
#2
Fanatic Member
The first on the right one is missing a "r" in "$userfile".
-
May 25th, 2002, 04:22 PM
#3
Fanatic Member
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
-
May 25th, 2002, 06:00 PM
#4
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.
-
May 25th, 2002, 06:55 PM
#5
Member
-
May 25th, 2002, 10:12 PM
#6
Thread Starter
Stuck in the 80s
-
May 25th, 2002, 10:14 PM
#7
Thread Starter
Stuck in the 80s
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.
-
May 25th, 2002, 10:18 PM
#8
Fanatic Member
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
-
May 25th, 2002, 10:20 PM
#9
Thread Starter
Stuck in the 80s
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!
-
May 25th, 2002, 10:21 PM
#10
Thread Starter
Stuck in the 80s
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.
-
May 25th, 2002, 10:25 PM
#11
Fanatic Member
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
-
May 25th, 2002, 10:29 PM
#12
Thread Starter
Stuck in the 80s
See! When you talk to me like I'm 10, it all makes sense. I understand what you mean now. Thanks for your help
-
May 25th, 2002, 10:34 PM
#13
Fanatic Member
hey no problem.
-
May 25th, 2002, 10:44 PM
#14
Thread Starter
Stuck in the 80s
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)?
-
May 25th, 2002, 10:45 PM
#15
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.
-
May 25th, 2002, 10:50 PM
#16
Thread Starter
Stuck in the 80s
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?
-
May 25th, 2002, 11:48 PM
#17
-
May 26th, 2002, 02:19 AM
#18
Frenzied Member
Any idea why they are changing it?
-
May 26th, 2002, 10:33 AM
#19
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.
-
May 26th, 2002, 12:45 PM
#20
Thread Starter
Stuck in the 80s
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?
-
May 26th, 2002, 01:35 PM
#21
Frenzied Member
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
-
May 26th, 2002, 05:25 PM
#22
Thread Starter
Stuck in the 80s
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.
-
May 26th, 2002, 06:24 PM
#23
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.
-
May 26th, 2002, 06:57 PM
#24
Thread Starter
Stuck in the 80s
Thanks.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|