0

I want to build a working upload file form and I use codes in this tutorial - http://www.w3schools.com/PHP/php_file_upload.asp

Everything works well. The only problem is, the original code only includes file type of gif and jpg. I need png also.

What I did is modified this lines :

    > if ((($_FILES["file"]["type"] == "image/gif")
    || ($_FILES["file"]["type"] == "image/jpeg")
    || ($_FILES["file"]["type"] == "image/pjpeg"))

to this :

if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
|| ($_FILES["file"]["type"] == "image/png"))

but it turns error. Any advice?

1
  • Using IDEs like netbeans, eclipse, etc. provide syntax highlighting which make these class of errors like extra parentheses easy to spot. Commented Dec 28, 2010 at 14:55

3 Answers 3

5

remove the extra ) after pjpeg to make it look like this:

if (($_FILES["file"]["type"] == "image/gif") || 
($_FILES["file"]["type"] == "image/jpeg") || 
($_FILES["file"]["type"] == "image/pjpeg") || 
($_FILES["file"]["type"] == "image/png"))

There is also an extra ( before the IF which I have removed, but that could be a copy paste problem from you.

Sign up to request clarification or add additional context in comments.

Comments

0

There is a syntax error in the "if" statement:

Change

if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/pjpeg")) || ($_FILES["file"]["type"] == "image/png"))

to:

if (($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/pjpeg") || ($_FILES["file"]["type"] == "image/png"))

Comments

0

You could modify it like this to make it look nicer and easier to modify later on:

if(in_array($_FILES['file']['type'], array('image/jpeg', 'image/pjpeg', 'image/gif', 'image/png'))

Now if you need to add more image types, you can just add a value to the array.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.