blueman378 Posted September 19, 2007 Share Posted September 19, 2007 ok what i want is so that i can get a picture and add it into a page using php eg ---Body start--- content more content a picture (i want to insert a picture here) (i want it insert the content here) content another picture ---body end--- so how would i go about doing this from a form eg a user uploads a picture it will add it in where i have shown and they can choose a description to go under the picture cheers matt Quote Link to comment Share on other sites More sharing options...
blueman378 Posted September 19, 2007 Author Share Posted September 19, 2007 is there something wrong with my question noone is answering Quote Link to comment Share on other sites More sharing options...
AdRock Posted September 19, 2007 Share Posted September 19, 2007 I suppose you could have a div with no specific height given to it so if it is empty then you wopn't see empty space. I would have a form where you can upload an image and the content maybe on another page and on th epoage in question, in the div connect to the database and get that record that you want to display. Also when you save the content, save the filename in the database also so you can use it as a reference You could do something like this <?php /** * Change the email address to your own. * * $empty_fields_message and $thankyou_message can be changed * if you wish. */ // This is displayed if all the fields are not filled in $empty_fields_message = "<p>Please go back and complete all the fields in the form.</p>Click <a class='two' href='javascript:history.go(-1)'>here</a> to go back"; // This is displayed when the email has been sent $thankyou_message = "<p>Thankyou. Article successfully added.</p>"; //This is the directory where images will be saved $target = "../images/"; $target = $target . basename( $_FILES['image']['name']); //This gets all the other information from the form $name = addslashes($_POST['txtName']); $message = addslashes($_POST['txtMessage']); $pic=($_FILES['image']['name']); $th_file_name = "../images/large/" . $_FILES['image']['name']; if (!empty($pic)) { $imagepath = $_FILES['image']['tmp_name']; // Load image $image = open_image($imagepath); if ($image == false) { die ('<strong>You uploaded an invalid image. Please go back and try again.</strong>'); } // Get original width and height $width = imagesx($image); $height = imagesy($image); // Percentage? if (!empty($_POST['percent']) AND is_numeric($_POST['percent'])) { $percent = floatval($_POST['percent']); $percent = $percent/100; $new_width = $width * $percent; $new_height = $height * $percent; // New width? Calculate new height } elseif (!empty($_POST['new_width']) AND is_numeric($_POST['new_width'])) { $new_width = floatval($_POST['new_width']); $new_height = $height * ($new_width/$width); // New height? Calculate new width } elseif (!empty($_POST['new_height']) AND is_numeric($_POST['new_height'])) { $new_height = floatval($_POST['new_height']); $new_width = $width * ($new_height/$height); // New height and new width } elseif (!empty($_POST['height']) AND is_numeric($_POST['height']) AND !empty($_POST['width']) AND is_numeric($_POST['width'])) { $new_height = floatval($_POST['height']); $new_width = floatval($_POST['width']); } else { die ('<strong>You didn\'t specify any resizing options.</strong>'); } // Resample $image_resized = imagecreatetruecolor($new_width, $new_height); imagecopyresampled($image_resized, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height); // Display resized image imagejpeg($image_resized,$th_file_name,100); } // Display the upload form: if (!isset($_POST['txtName'])) { ?> <h2>Add a general article</h2> <form enctype="multipart/form-data" method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>"> <p class="style1">Please enter a title for the general article. <input class="form" type="text" title="Please enter a title for the general article" name="txtName" size="30"/></p> <p class="style1">Please enter the content for the general article. <textarea class="form" title="Please enter the content for the general article" name="txtMessage" rows="25" cols="30"></textarea></p> <fieldset> <legend><b>Image Dimensions</b></legend> <div><label for="image">Image:</label> <input type="file" name="image" /><br /></div> <div><label for="percent">Resize to:</label> <input type="text" name="percent" size="2" /> % (percentage)</div> <div><label for="new_width">OR new width:</label> <input type="text" name="new_width" size="2" /> pixels (height will be calculated automatically)<br /></div> <div><label for="new_height">OR new height:</label> <input type="text" name="new_height" size="2" /> pixels (width will be calculated automatically) <br /></div> <div><label class="left" for="both">OR new height and new width:</label> <input type="text" name="width" size="2" /> pixels<br /> <input type="text" name="width" size="2" /> pixels<br /></div> </fieldset> <p> <input class="submit-button" style="margin-left:0" type="Submit" value="Submit" /><input class="submit-button" style="margin-left:2px" type="reset" value="Reset" /> </form> <?php } elseif (empty($name) || empty($message)) { echo $empty_fields_message; } else { // Stop the form being used from an external URL // Get the referring URL $referer = $_SERVER['HTTP_REFERER']; // Get the URL of this page $this_url = "http://".$_SERVER['HTTP_HOST'].$_SERVER["REQUEST_URI"]; // If the referring URL and the URL of this page don't match then // display a message and don't send the email. if ($referer != $this_url) { echo "You do not have permission to use this script from another URL."; exit; } include_once("../includes/connection.php"); $date = date("Y/m/d"); $query = "INSERT INTO articles VALUES ('','$name','$message','$date','$pic','n')"; mysql_query($query); mysql_close(); //Display the thankyou message //echo $thankyou_message; } function open_image ($file) { # JPEG: $im = @imagecreatefromjpeg($file); if ($im !== false) { return $im; } # GIF: $im = @imagecreatefromgif($file); if ($im !== false) { return $im; } # PNG: $im = @imagecreatefrompng($file); if ($im !== false) { return $im; } # GD File: $im = @imagecreatefromgd($file); if ($im !== false) { return $im; } # GD2 File: $im = @imagecreatefromgd2($file); if ($im !== false) { return $im; } # WBMP: $im = @imagecreatefromwbmp($file); if ($im !== false) { return $im; } # XBM: $im = @imagecreatefromxbm($file); if ($im !== false) { return $im; } # XPM: $im = @imagecreatefromxpm($file); if ($im !== false) { return $im; } # Try and load from string: $im = @imagecreatefromstring(file_get_contents($file)); if ($im !== false) { return $im; } return false; } ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.