tags:

views:

36

answers:

1

When I sent an image to the code below, uploadImage.php, through a POST method, how do I add a String parameter?

<?php
$hasError = false;
foreach( $_FILES as $i=>$file )
{
    if ( $file['error'] )
    {
        $hasError = true;
    }
}
if ( ! $hasError )
{
    $myFilePath = '_uploads/'.'_'.$file["name"];
    $dta = file_get_contents($file['tmp_name']);
    file_put_contents($myFilePath, $dta);
}
else
{
    echo('Stick custom error message here');
}
?>
+2  A: 

If I understand you correctly, add to the page from where the form is submitted an input:

<form ....>
...
<input type="text" name="my_key" value="default value" />
</form>

You can then access it from $_POST:

if (array_key_exists("my_key", $_POST) && !is_array($_POST["my_key"]))
    echo htmlentities($_POST["my_key"]);
else
    //error handling; field was not included or multiple values were given
Artefacto