0
votes

Excuse me if my english is not grammatical....

Is it possible to replace $_POST with $_FILES ?

In my program, i copied all information of a register form to an array

Like This

$this->RegistrationFields['profile_img'] = array( 'name' => 'Image','type' => 'BLOB', 'table' => 'users', 'field' => 'profile_img');

and get values using foreach

foreach( $this->RegistrationFields as $fields => $values )

after that it check for field is set or not

if( ! isset( $_POST['register_' . $fields] ) || $_POST['register_' . $fields] == '' )
        {
            $this->submittedValues[ $fields ] = $_POST['register_' . $fields];
            $this->errorLabels['register_' . $fields] = 'error';
            $this->errors[] = 'Field ' . $data['name'] . ' cannot be empty';
        }

But the problem is that it always shows error message when uploading images,

I guess i have to replace the $_POST with $_FILES while checking image,

SO i put

if ($fields == 'profile_img')
{
    //replace $_POST with $_FILES   
}

just above the ISSET condition

So my question is :

Is there an inbuld function to replace $_POST with $_FILES???? in *PHP*

EDIT : Or else i could use str_replace?

1
Why do you look in a wrong array then? - zerkms
to replace php tag. Wait, what? - Bojangles
@JamWaffles : I mean $_POST with $_FILES??? - Peace Lover
Superglobals are not read-only so you can do almost everything you want with them. Of course, changing their default meaning can do no good to your code base. - Álvaro González

1 Answers

1
votes

$_POST holds data coming from the HTTP POST request to the page.

$_FILES holds all data pertaining to a file that's been uploaded.

You can't swap the two over. If you want to see if a file has been uploaded, try using

isset($_FILES['name'])

Or (better still):

if(!$_FILES['error'])

Which will see if there's been an error uploading the file anywhere.