I just started learning PHP in my internee from school My problem is that I haven't learned PHP at school yet. So in my internee they have been giving me some exercises for me to do, but I got totally stuck in one of them.
The exercise is to create a form that allows the user to upload a file (until here it was okay, the problem comes next). Having this 1st part done I have to find a way to only allow text files with the formats of PHP, Javascript and HTML. And here I got stuck, I tried with if
's, I tried with arrays, and nothing works.
Please can anyone help me?
I've tried:
if (($_POST['extension'] != $allowed ) && (empty($_POST['name']))) {
echo "error message";
and
$file_name = $_FILES['file_name']['name'];
$ext = pathinfo($file_name, PATHINFO_EXTENSION);
if (!in_array($ext,$allowed)) {
echo "error message";
The second one worked as well as the 1st one. I'm using the $_POST
method.