/    Sign up×
Community /Pin to ProfileBookmark

Checking for file extensions?

Hi Guys,

I have a form for uploading files to my website and conditions to state what types of files are uploaded where.

However It throws up $error even though you are uploading the correct extentions:

[code]
$puzzle= “upload/$one”.$_FILES[‘ufile’][‘name’][0];
$pdf= “upload/$two”.$_FILES[‘ufile’][‘name’][1];
$png= “upload/$three”.$_FILES[‘ufile’][‘name’][2];

//copy file to where you want to store file
move_uploaded_file ($_FILES[‘ufile’][‘tmp_name’][0], $puzzle);
move_uploaded_file($_FILES[‘ufile’][‘tmp_name’][1], $pdf);
move_uploaded_file($_FILES[‘ufile’][‘tmp_name’][2], $png);

//check file extensions
$ext_puz = $puzzle[count($puzzle) – 1];
$ext_pdf = $pdf[count($pdf) – 1];
$ext_png = $png[count($png) – 1];

// ** Check for Required Fields with IF statements **
if (empty($title)){
$error = “** You forgot to enter a title **”;
$flag=1;
} if (empty($type)){
$error = “** Error: You forgot to enter the type of puzzle! **”;
$flag=1;
} if (empty($about)){
$error = “** Error: You forgot to enter any about info! **”;
$flag=1;
} if (empty($_FILES[‘ufile’][‘tmp_name’][0]) || (strtolower($ext_puz) != “jpz”)) {
$error = “** Error: You forgot to upload a puzzle file (jpz)! **”;
$flag=1;
} if (empty($_FILES[‘ufile’][‘tmp_name’][1]) || (strtolower($ext_pdf) != “pdf”)) {
$error = “** Error: You forgot to upload a pdf! **”;
$flag=1;
} if (empty($_FILES[‘ufile’][‘tmp_name’][2]) || (strtolower($ext_png) != “png”)) {
$error = “** Error: You forgot to upload a png solution file! **”;
$flag=1;
}
[/code]

I’m a bit stumped! Any ideas?
[/quote]

Thanks

to post a comment
PHP

0Be the first to comment 😎

×

Success!

Help @chrisb spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 3.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,

tipper: Anonymous,
tipped: article
amount: 10 SATS,
)...