user1187135
user1187135

Reputation:

How do I check if a file is selected for <input type="file"> in PHP?

I want to check if the user has selected an image for upload. What is the php script to do that after the user has clicked submit...

I tried file_exist(), but that expects a string rather than an array and it seems that only works for an absolute path. Since I don't know which folder the user is going to upload from, this doesn't work.

Can someone help?

Upvotes: 0

Views: 477

Answers (2)

xdazz
xdazz

Reputation: 160833

You need to use the super global variable $_FILES.

More info.

Upvotes: 0

Brad
Brad

Reputation: 163272

Take a look at the $_FILES superglobal.

Tizag Tutorial: http://www.tizag.com/phpT/fileupload.php

If you do a print_r($_FILES), you will see everything you need.

Upvotes: 3

Related Questions