Show image in new automaticly created page

i here is my script when Someone upload image it saves data to the database and also it creates a page with title filled up in form. See the $template in PHP script it is the page which is generated it is empty but I want to show image in this page when image was uploaded.

What this script can do: When someone upload image It automatically creates a page with the url which was filled in form in title section It saves data to database in table save_data with these info id, username, link, type, size, name

What I want When it creates a page it show a image which was uploaded

PHP Upload Script with image creation:

[php]<?php
if(!isset($_COOKIE[‘loggedin’])){
header(“location:index.php”);
}

session_start();

if(!isset($_SESSION[‘user’])){

header(“location: index.php”);
}
else {

?>

<?php include("connection.php"); $current_page_URL =(isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"]==”on”) ? “https://” : “http://”; $current_page_URL = $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"]; $allowed_filetypes = array('.jpg','.JPG','.jpeg','.png','.gif','.JPEG','.PNG','.GIF'); $max_filesize = 10485760; $upload_path = 'uploads/'; $filename = $_FILES['image_file']['name']; $ext = substr($filename, strpos($filename,'.'), strlen($filename)-1); if(!in_array($ext,$allowed_filetypes)) die('The file you attempted to upload is not allowed.'); function bytesToSize1024($bytes, $precision = 2) { $unit = array('B','KB','MB'); return @round($bytes / pow(1024, ($i = floor(log($bytes, 1024)))), $precision).' '.$unit[$i]; } $sFileName = $_FILES['image_file']['name']; $sFileType = $_FILES['image_file']['type']; $sFileSize = bytesToSize1024($_FILES['image_file']['size'], 1); if (file_exists("uploads/" . $_FILES["image_file"]["name"])) { echo $_FILES["image_file"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["image_file"]["tmp_name"], "uploads/" . $_FILES["image_file"]["name"]); echo "Stored in: ".$_SERVER["SERVER_NAME"]. "/uploads/" . $_FILES["image_file"]["name"]; } $savefile = $_SERVER["SERVER_NAME"]. "/uploads/" . $_FILES["image_file"]["name"]; $insert_query = "insert into save_data (username, Name, Type, size, link) values ('".$_SESSION['user']."','$sFileName','$sFileType','$sFileSize','$savefile')"; if(mysql_query($insert_query)){ echo ""; //if the notice is set then display it if(isset($notice)){echo $notice;} }}[/php] //Template of PAGE [code] $template = <<<EOD EOD;[/code] //Page Creation Script [code]//handle the posted form if(isset($_POST['title'])){ //replace the areas of the template with the posted values $page = str_replace('',htmlentities($_POST['title']),$template);; //create a name for the new page $pagename =($_POST['title']).'.php'; //db connect & select $db=mysql_connect('localhost','root','123'); mysql_select_db('user'); //check if page already exists $result = mysql_query('SELECT pagename from pages WHERE url="'.mysql_real_escape_string($pagename).'"'); if(mysql_num_rows($result)>=1){ $notice = '

Page already created ./pages/'.$pagename.'

'; }else{ //inset new page into db mysql_query('INSERT into pages (`id`,`title`,`comment`,`url`)VALUES("", "'.mysql_real_escape_string(htmlentities($_POST['title'])).'", "'.$pagename.'")'); //put the created content to file file_put_contents('./pages/'.$pagename,$page); //make a notice to show the user $notice = '

New Page created ./pages/'.$pagename.'

'; } } ?>[/code]

HTML Page

[code]

Pure HTML5 file upload | Script Tutorials

You can select the file (image) and click Upload button

        <div class="upload_form_cont">
            <form id="upload_form" enctype="multipart/form-data" method="post" action="upload.php">
                <div>  <p>Title:<input type="text" name="title" size="31"></p>
                    <div><label for="image_file">Please select image file</label></div>

                    <div><input type="file" name="image_file" id="image_file" onchange="fileSelected();" /></div>
                </div>
                <div>
                    <input type="button" type="submit" value="Upload" onclick="startUploading()" />
                </div>
                <div id="fileinfo">
                    <div id="filename"></div>
                    <div id="filesize"></div>
                    <div id="filetype"></div>
                    <div id="filedim"></div>
                </div>
                <div id="error">You should select valid image files only!</div>
                <div id="error2">An error occurred while uploading the file</div>
                <div id="abort">The upload has been canceled by the user or the browser dropped the connection</div>
                <div id="warnsize">Your file is very big. We can't accept it. Please select more small file</div>

                <div id="progress_info">
                    <div id="progress"></div>
                    <div id="progress_percent">&nbsp;</div>
                    <div class="clear_both"></div>
                    <div>
                        <div id="speed">&nbsp;</div>
                        <div id="remaining">&nbsp;</div>
                        <div id="b_transfered">&nbsp;</div>
                        <div class="clear_both"></div>
                    </div>
                    <div id="upload_response"></div>
                </div>
                <div>


                </div>
            </form>

            <img id="preview" />
        </div>
    </div>
</body>
[/code]

Please give me Answer I am asking questions but not one is helping me :frowning:

Sponsor our Newsletter | Privacy Policy | Terms of Service