<?php 
$id=1;//you will have to change this. Basically each logged in member will have a unique id. 
if (isset ($_POST["image_processing"]) and $_POST["image_processing"] 
== 'saved_images') //Instead of uploading a new pic from the hard drive the user can browse the pics he previously uploaded on the server. The dialog has a button called brows server, when clicked the server will send back the existing pic for that specific member based on his id. 
{ 
        $files1 = scandir ("members/$id/figures"); 
        $file_list=''; 
        for ($i=2;$i<count($files1);$i++) 
                { 
                        $file_list .= $files1[$i].'<div id="feedback_container" style="width:400px; border:1px solid #000;padding: 5px;margin:auto;"><img id="image_to_insert" src="members/'.$id.'/figures/'.$files1[$i].'"></div>'; 
                } 
                echo $file_list; 
        exit(); 
} 

if (!file_exists("members/$id/figures")) //each member or website user will have his own folder to store the uploaded pic. So, we have to create it if it doesn’t exist ;) 
{ 
        mkdir("members/$id/figures",0755); 
} 
if ($_FILES['file']['tmp_name'] != "") 
        { 
                if (!preg_match("/\.(gif|jpg|png|jpeg)$/i", $_FILES['file'] 
['name'] ) ) { 

                                        $error_msg = '<div class="error_msg_container"> 
                                                        <h3>ERROR: Your image was not one of the accepted formats (gif, jpg, png, bmp), please tryagain.</h3></div>';//I thinks you don't need me to comment this part ;) 
                                        unlink($_FILES['file']['tmp_name']); 
                                        exit(); 

                } else { 
                                        $figure_name = $_FILES['file']['name']; 
                                        if (file_exists("members/$id/figures/".$figure_name)) 
                                        { 
                                                echo '<div style="color:#696969">This figure does already exist or an other figure has the same name. Please, remane your figure.</ 
div>';//Feedback to send if they already have sent a same picture. This will prevent multiple upload of the same pic. You can add a button that displays all previously uploaded pictures (a piece of cake ;)) 
                                                exit(); 
                                        } 
                                        $image_url="members/$id/figures/".$figure_name; 
                                        $place_file = move_uploaded_file( $_FILES['file']['tmp_name'], $image_url); 
                                        if($_FILES['file']['size'] >600000) 
                                        { 
                                                require_once ('_Class_Files/class.image-resize.php'); //This wonderful plugin will resize the pic so people if the uploaded picture to big it will be resized ;) 
                                                $obj = new img_opt(); 
                                                $obj->max_width(400); 
                                                $obj->max_height(400); 
                                                $obj->image_path($image_url); 
                                                $obj->image_resize(); 
                                        } 

                } 
                echo '<div id="feedback_container" style="width:400px; border:1px solid #999;padding:5px;margin:auto;"><img id="image_to_insert" width="400" src="'.$image_url.'"></div>'; //here is our attribute that will be received by the iframe. 
    } else { 
        echo '<div id="feedback_container" style="border:1px solid #696969;padding:5px;text-align:center;color:#fba7ae">You can not upload an umplty file!</div>';//just in case if someone thinks that he/she can send an empty file (how knows!) :=) 
} 
?> 