The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Shouldnt this be echoing something different?
allenph
post Feb 23 2012, 12:29 AM
Post #1


Novice
**

Group: Members
Posts: 21
Joined: 15-February 12
Member No.: 16,477



I know I post a thousand threads sorry... so my issue is...

<?php
$uploaded_boolean = file_exists($_FILES["uploaded_avatar"]["…
$gif = '.gif';
$jpg = '.jpg';
$jpeg = '.jpeg';
$png = '.png';
$jpeg1 = 'jpeg';
$gif1 = 'gif';
$jpg1 = 'jpg';
$png1 = 'png';
$max_file_size = '1048576';
$new_avatar = $_FILES['uploaded_avatar']['name'];
$avatar_ext = end(explode('.', $new_avatar));
if (isset($_POST['change_submit1'])) {
if ($_SESSION['logged_in'] != '1') {
echo 'You need to be logged in!';
} elseif ($_POST['change_box1'] != 'CHANGE') {
echo 'You must fill in the "CHANGE" box!';
} elseif ($uploaded_boolean == False) {
echo 'No file selected!';
} elseif (($avatar_ext != $jpg1) && ($avatar_ext != $png1) && ($avatar_ext != $gif1) && ($avatar_ext != $jpeg1)) {
echo 'File format not supported!';
} elseif ($_FILES["uploaded_avatar"]["size"] > $max_file_size) {
echo 'File is too big!';
}
}
?>

It seems like it would work...but it outputs no file selected even though I want it to say File format not supported. They are in the correct order. am i checking for the file upload incorrectly or something? help please!
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Brian Chandler
post Feb 24 2012, 12:09 AM
Post #2


Jocular coder
********

Group: Members
Posts: 2,460
Joined: 31-August 06
Member No.: 43



QUOTE
I know I post a thousand threads sorry...


That's not really a problem, but it helps if you can reduce the simple volume of code in your question.

There is *lots* that could be trimmed out anyway -- what is the point of having a *variable* $jpg whose value is always(?) 'jpg'? (Ans: none)

What you need hereabouts is an array that holds the valid extensions:

$validext = array('jpg', 'gif', 'png');

... or something like that. Then you check if the extension is valid using in_array() (which you look up in the manual for the details). This gets rid of all these sections where you repeat essentially the same code for a number of cases.

Actually you should read up on the gd library if you are having user upload "avatars" (which I presume are meant to be small images), because people will upload all sorts of bloated junk, and you should check they are valid image files and resize them appropriately. After all, there is nothing to stop a user renaming virus.exe as picture.jpg

Again, you have to find out why your program isn't working as you expect (of course it's "working", it just isn't quite the right program), but adding debugging echos. What _is_ the value of $avatar_ext ??
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 28th March 2024 - 04:00 AM