Checking for file extensions?

2012-01-04  Source: Original Site  Category:PHP  Views:0 


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:

$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 **";
} if (empty($type)){
$error = "** Error: You forgot to enter the type of puzzle! **";
} if (empty($about)){
$error = "** Error: You forgot to enter any about info! **";
} if (empty($_FILES['ufile']['tmp_name'][0]) || (strtolower($ext_puz) != "jpz")) {
$error = "** Error: You forgot to upload a puzzle file (jpz)! **";
} if (empty($_FILES['ufile']['tmp_name'][1]) || (strtolower($ext_pdf) != "pdf")) {
$error = "** Error: You forgot to upload a pdf! **";
} if (empty($_FILES['ufile']['tmp_name'][2]) || (strtolower($ext_png) != "png")) {
$error = "** Error: You forgot to upload a png solution file! **";

I'm a bit stumped! Any ideas?

Related articles
  • Checking for file extension 2013-04-29

    I have a class that allows certain types of files to be uploaded. Currently, it checks the files ContentType, however for example I want to allow .csv files to be uploaded and it's ContentType is: application/octet-stream but so is .ini and .dbo file

  • Checking for file extensions? 2012-01-04

    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: $puzzle= "upload/$one".$_FILES['ufile']['name'][0]; $pdf

  • Checking for file extension (in a string) 2014-07-29

    What's the easiest way to find out the filetype of a URL that's stored within a variable? I'm looking to write something that will I want to do this: $url = if $url contains .swf, <embed flash> else if $url contains .g

  • Ubuntu Beryl: Checking for XComposite extension : failed 2012-09-23

    I just installed Beryl on Edgy (ati xpress 200 video with ati drivers) using: The installation seemed to work fine. When I started beryl-manger it started up but I had the following error in the terminal. ***

  • Check for file modifications by external sorces 2012-09-26

    I'm wondering is there simple way in python to check for file modifications by external sources similar to what existing in gedit or drpython (text editors). So far I was able to check for file modification but I don't know how to "call" this functio

  • Checking for file differences 2014-04-12

    I am writing an application for work that will be distributed across about 200 servers, installing is going to be a big enough pain but what I am looking to do is ensure that after the application is installed it can doing a daily check against a mas

  • How to check for file existance/validity? 2014-04-13

    I am new to these forums, and can already tell that I am going to like this place. Anyways, I am currently coding my first app in Visual C++ 6.0, however I have also recently also learned Visual Basic 6.0. The app will simply use nested IF ELSE funct

  • check for file before accepting registration 2014-08-04

    I have this system where users upload their files into their directory to be viewed by themselves and then these files are copied to a general directory to be viewed by the administration. After uploading the files users are to register. Right now an

  • _access (check for file/directory existence ) 2014-10-01

    Hi I use the function _access to check for file/directory existence in my program, but I have noticed that the function can't deal with longfilenames. Are there anyone who knows a new function to use?

  • Oracle check for file name using FILE_BROWSE 2015-03-01

    I have a file_browse item in an APEX page and a submit button which loads the contents of the file into an oracle table. everything is working, but I need to put in a check for file name. Meaning, user is only allowed to load a file with a very speci

  • Ubuntu Default aplication launch for file extensions - How? 2012-09-15

    Where can I define or link file extensions to open with a default aplication? For example I want *.mp3 or *.wvm to be open by default(on double click) by gmplayer.

  • Check for file when installing a application 2013-10-07

    is there a way to check for the existence of a specific file during install process of an application?

  • Checking for files in a directory 2014-01-27

    How can I check for the existence of a file in a directory? I need to check it before overwriting the file. Thx, Ralf.

  • Timed loop to check for file 2015-03-27

    Very new to Python and still stumbling around but need some help. As part of a larger script, I'd like to run a routine that checks for the existence of a file once a second for about 3 minutes and if it suddenly appears, carry on with the rest of th

  • Checking for files? 2015-05-03

    I want to be able to check and find files if they exist. The only problem is i don't know specifically what the file name will be. I know that a certain number will exist in the file name (e.g. 8056) but there will be other letters and numbers follow

  • How do I check for File Not Found 2014-08-04

    I am linking to a .gif image that is sometimes not posted yet. How do I check for this so that if it is not posted, I can make it go to a backup .gif?

  • Check for file existance 2013-08-15

    I have a PHP website and it's running great. The way it works is that I have a template page, thanks to sarah, that is called with every page and then a secondary page is called for the unique information. Here is how I would access my contacts page:

  • Check for file 2014-05-18

    What I'm TRYING (and failing) to do is very simple, check a directory for XXX file. I know the name of the file, and I know the directory. I don't want to do a listing of the directory and then check the list, that would be a huge load on the server.

  • Launching application for file extension 2014-06-23

    what do I need to do in order to launch the proper application for a file with a certain extension. E.g. I have a file called bla.gif now I would like to launch this file with its registered application (in that case prob. IE5). Can aynbody help me P

  • Check for file tampering? 2015-04-19

    I was just wondering if anyone ( usin PHP 4.0.1pl2 ) has written a script that computes a hash value for a file ( txt or otherwise ), then stores the newly computed value in a safe location, allowing the admin. to check the same file at a later date