The subject of this may be confusing so I will elaborate, below is my latest attempt at code to upload an image to a folder, I know this may seem like an easy task for some but I have additional functions to add after I get the basics down. Anyway, this version of the code appears to work flawlessly as far as uploading the image to the folder my only problem is error reporting, if the image is uploaded to the folder with no errors then after the upload is complete a line of text should display in green saying “Upload Completed Successfully!” and that doesn’t happen. I know the image is uploaded because I have the upload folder open on another monitor and I can see as the image pops on the screen as it is uploaded to the folder. I’m sure, as usual, I’ve left out some punctuation or I need an additional if (empty($errors)) before the $errrors[]=
Here’s the code
[php]
Untitled 2
Image:
<?php
// After the form loads, if the submit button is pressed
if (isset ($_POST['submit']))
{
$errors=array(); //declaration of an array which we will us to display erros
$image=$_FILES['image']['name'];// taking the file name and storing in variable
$file_tmp=$_FILES['image']['tmp_name'];// this is a temporary variable
// now if the image name is empty...
if (empty($image))
{
$errors[]="Please Enter All Fields";// showing the error as an array
}
if (empty($errors))// now if the error array is empty this means we have no errors and all things are ok
{
// Here is where we upload a copy of the image to our folder 'uploads/images/'
move_uploaded_file ($file_tmp, 'uploads/images/'.$image);
//now we show the errors in a foreach loop, if no errros then 'Upload Completed Successfully' should display in GREEN!
$errors[]="
Upload Completed Successfully!";
}
else
{
foreach ($errors as $err)
{
echo "
$err";
}
}
}
?>
[/php]