Connecting Tech Pros Worldwide Forums | Help | Site Map

Form Question

Alec
Guest
 
Posts: n/a
#1: Sep 8 '08
Sorry simple question....

Just started playing around with forms and have tried the following to
enter both a text title and file to upload.

The routine works OK to check to see if the submit button is pressed,
but I tried to also check to see if a file is actually selected to
upload with the (isset ($_FILES['new_image'])).

However even if no files are selected from the form, the IF statement
processes this as if there have been and echos "File Selected".

What obvious thing have i missed...

THANKS

<form action="<?php echo $_server['php-self']; ?>" method="post"
enctype="multipart/form-data" id="something" class="uniForm">
<p>Select Image File:<input name="new_image" id="new_image" size="30"
type="file" class="fileUpload" /></p>
<p>Short Article Title: <input type="text" name="short_title"></p>
<button name="submit" type="submit" class="submitButton">Upload Image</
button>
</form>

<?php
if(isset($_POST['submit'])){

if (isset ($_FILES['new_image']))
{
echo "File Selected";
echo $_FILES['new_image']['name'];
}

echo "post sent";
$short_title = $_POST['short_title'];
echo $short_title;
}

?>

Alec
Guest
 
Posts: n/a
#2: Sep 8 '08

re: Form Question


OK seem to have solved it with the following..

if(isset($_POST['submit'])){

$file_tmp = $_FILES['new_image']['tmp_name'];
$file_name = $_FILES['new_image']['name'];

if (is_uploaded_file($file_tmp)) {

echo "File Selected";
echo $_FILES['new_image']['name'];


}

echo "post sent";
$short_title = $_POST['short_title'];
echo $short_title;

}

Thanks anyway...
Sjoerd
Guest
 
Posts: n/a
#3: Sep 8 '08

re: Form Question


Alec wrote:
Quote:
I tried to also check to see if a file is actually selected to
upload with the (isset ($_FILES['new_image'])).
The right way for this seems to be checking
$_FILES['new_image']['error']. It will be UPLOAD_ERR_NO_FILE.
Closed Thread