2

Im trying to build an image upload for my site, I have the following only nothing is output at all, yet my page renders okay? Can anybody see where I may be going wrong?\

    //if they DID upload a file...
if($_FILES['profile_image']['name'])
{
    //if no errors...
    if(!$_FILES['profile_image']['error'])
    {
        //now is the time to modify the future file name and validate the file
        $new_file_name = strtolower($_FILES['profile_image']['tmp_name']); //rename file
        if($_FILES['profile_image']['size'] > (1024000)) //can't be larger than 1 MB
        {
            $valid_file = false;
            $message = 'Oops!  Your file\'s size is to large.';
        }

        //if the file has passed the test
        if($valid_file)
        {
            //move it to where we want it to be
            move_uploaded_file($_FILES['profile_image']['tmp_name'], 'uploads/'.$new_file_name);
            $message = 'Congratulations!  Your file was accepted.';
        }
    }
    //if there is an error...
    else
    {
        //set that to be the returned message
        $message = 'Ooops!  Your upload triggered the following error:  '.$_FILES['profile_image']['error'];
    }
}

else {
echo    'success';
    }

<form method="post" action="./process-signup.php" enctype="multipart/form-data" >


    <input type="file" class="profile_image text-input" name="profile_image" placeholder="Upload a picture"/><br />
    <input type="submit" id="signup-com-btn" value="Complete Signup" />

</form>
Liam
  • 9,725
  • 39
  • 111
  • 209

1 Answers1

1

In you PHP script, you have assigned the variable $message to different values, on different stages, like this:

 $message = 'Oops!  Your file\'s size is to large.';
 $message = 'Congratulations!  Your file was accepted.';   
 $message = 'Ooops!  Your upload triggered the following error:  

but you are not actually echoing it out, so you are not getting any message.

SO, I would recommend echoing it, obviously.

samayo
  • 16,163
  • 12
  • 91
  • 106
  • I've tried `echo` my messages too @PHPNOOB but still nothing is output – Liam Jun 03 '13 at 22:10
  • Well, the problem could be, something to do with `Variable scope` So, just don't assign, the values, and just echo them from inside the script like `echo 'Oops! Your file\'s size is to large.';` – samayo Jun 03 '13 at 22:12