PHP - Position Images Using Gd Library?
Hey Guys
Ok I can postion text using the GD library using the following: Code: [Select] imagefttext($rImg, 13, 0, 105, 55, $black, $font_file,$Username); How would do the same using an image? For example Code: [Select] whateverfunction($rImg, 13, 0, 105, 55,$ImagePath); Thanks a million. Similar TutorialsHey guys, I have created combined images from edits I had laying around. I have a chair, and i'm trying to combine different colored tops with a pair of legs using a radio button to choose the top color. Here is what I have so far for the form page: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Untitled Document</title> </head> <body> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <label>Seat Color Choices:</label><br> Red<input type="radio" name="color" value="red" id="red" onFocus="getElementById('config').src = 'red.php'" > Orange<input type="radio" name="color" value="orange" id="orange" onFocus="getElementById('config').src = 'orange.php'" > Ivory<input type="radio" name="color" value="ivory" id="ivory" onFocus="getElementById('config').src = 'ivory.php'" > Black<input type="radio" name="color" value="black" id="black" onFocus="getElementById('config').src = 'black.php'" > </form> <img src="black.php" id="config" alt="color choice for lola chair"> </body> </html> ...and here is one of my image files for an example: <?php //Report any errors ini_set ("display_errors", "1"); error_reporting(E_ALL); //Set the correct content type header('content-type: image/jpeg'); $base = imagecreatefromjpeg('lola_base.jpg'); $red = imagecreatefromgif('lola_red.gif'); $orange = imagecreatefromgif('lola_orange.gif'); $ivory = imagecreatefromgif('lola_ivory.gif'); $black = imagecreatefromgif('lola_black.gif'); imagecopy($base, $red, 0 , 0 , 0, 0,250, 250); imagejpeg($base); //Clear up memory used imagedestroy($base); ?> The problem is, I need to be able to dynamically change which images are being combined. I can't have a different file for each combo (ex. red.gif, black.gif, ivory.gif, etc.) I need it to create them on cue from a single file/function. Is there a way to do that with PHP GD library? Hi, how i could do this with gdlibrary: I make image with imagecreatefrompng , and that is my pictures background. Then I add image there, and that is my bird flying in the background. that is only example, i wanna just add image to image Hi everyone. There are two nice script which are advanced for me to understand. There is a Knockout tournament scheduler class that makes image of the bracket. and there is a code that makes html of the bracket with jquery. I want to use the class with jquery. but I don't know how to do that and where to start. the class below needs to implement to this http://whileonefork.blogspot.com/2010/10/jquery-json-to-draw-elimination-single.html I attached the php script. please help me! Code: [Select] <?php class KnockoutGD extends Knockout { private $im = null; // GD-lib image resource. private $tc = 0; // Text color. public function getImage($tourName = '') { /* Returns a GD-lib image resource */ // Initial testing. if (empty($this->roundsInfo)) return null; // Dimensional parameters. $fh = imagefontheight(FONT); $fw = imagefontwidth(FONT); $lpad = 30; // Line (branch) padding before and after competitor names and after scores. $hpad = 20; // Outer horizontal image padding. $vpad = 60; // Outer vertical image padding. $lw = $this->getStrLen()*$fw + 3*$lpad; // Line (branch) width. Where getStrLen() gets the length of the longest string used in the image. // Initial calls. $dimensions = $this->getDimens($fh, $lw, $hpad, $vpad); $this->im = imagecreate($dimensions['x'], $dimensions['y']); $bg = imagecolorallocate($this->im, 255, 255, 255); // Set background color. $this->tc = imagecolorallocate($this->im, 0, 0, 0); // Text color. $this->mkStr($dimensions['x'] - $hpad - imagefontwidth(LFONT)*strlen($tourName), $dimensions['y'] - $vpad/2, $tourName, LFONT); // Print tournament name. // Initial positioning values from which drawing begins. $rx = $hpad; // Round X-position. $ry = $vpad; // Round Y-position. $depth = 1; // Branch depth. // Start drawing the tournament bracket/tree. foreach ($this->roundsInfo as $r => $info) { $n = $info[1]; // Number of expected players in round $r. // If a match is no yet created, then a placeholder is made so that the bracket structure is still printable. for ($m = 0; $m <= $n/2 - 1; $m++) { if (!$this->isMatchCreated($m, $r)) { $this->bracket[$r][$m]['c1'] = $this->bracket[$r][$m]['c2'] = null; $this->bracket[$r][$m]['s1'] = $this->bracket[$r][$m]['s2'] = -1; } } // Now we generate round branches. $x = $rx; $y = $ry; $bheight = pow(2, $depth) * $fh; // This is the height of a match-branch, which increases as the tree depth increases. ksort($this->bracket[$r]); foreach ($this->bracket[$r] as $m) { for ($i = 1; $i <= 2; $i++, $y += $bheight) { $this->mkStr($x+$lpad, $y, $m['s'.$i] == -1 ? 'Undecided' : $m['c'.$i]); $this->mkStr($x+$lw-$lpad, $y, $m['s'.$i] == -1 ? '?' : $m['s'.$i]); $this->mkLine($x, $y+$fh, $x+$lw, $y+$fh); } $this->mkLine($x+$lw, ($y+$fh)-$bheight, $x+$lw, ($y+$fh)-2*$bheight); } // Get ready for next loop. $rx += $lw; $ry += $bheight/2; $depth++; } // Add final branch/line for the tournament winner $fr = end(array_keys($this->roundsInfo)); // Final round. $s1 = $this->bracket[$fr][0]['s1']; $s2 = $this->bracket[$fr][0]['s2']; $winner = (!array_key_exists(0, $this->bracket[$fr]) || $s1 == -1 || $s2 == -1 || $s1 === $s2) ? '?' : (($s1 > $s2) ? $this->bracket[$fr][0]['c1'] : $this->bracket[$fr][0]['c2']); $this->mkStr($rx+$lpad, $ry, 'Winner: ' . $winner); $this->mkLine($rx, $ry+$fh, $rx+$lw, $ry+$fh); // Now, we print the round titles. array_push($this->roundsInfo, array('Champion', 1)); // Add fictitious round for printing purposes only. foreach (array_reverse($this->roundsInfo) as $r) { $this->mkStr($rx+$lpad, $vpad/3, $r[0], LFONT); $rx -= $lw; // Move back one round/column. } array_pop($this->roundsInfo); // Remove fictitious round entry again. return $this->im; } private function mkLine($x0, $y0, $x, $y) { /* Wrapper for function that creates a line. */ imageline($this->im, $x0, $y0, $x, $y, $this->tc); } private function mkStr($x, $y, $str, $font = false) { /* Wrapper for function that writes a string. */ imagestring($this->im, $font ? $font : FONT, $x, $y, $str, $this->tc); } private function getDimens($fontHeight, $lineWidth, $horizPad, $vertPad) { /* Returns image dimensions based on the tournament bracket. */ /* Vertically: Each match-branch is outputted like this: Team A ----------- Padding Team B ----------- Padding ... where "Padding" and "Team X" are of height $fontHeight, and "------" are branch lines with approximately no height. Horizontally: Each branch is outputted like this: ----- Team A ------ | ----- Team C ------ | ----- Team B ------ ... where "Team X" branch has an absolute length of $lineWidth. The above therefore illustrates a length of 2*$lineWidth. The image length, $x, must be: $horizPad + number_of_rounds * $lineWidth + $horizPad And the image height, $y, must be: $vertPad + number_of_matches_in_first_round * 4*$fontHeight + $vertPad ... since the first round contains the most matches. */ $frGames = count($this->bracket[1]); // Number of games in the first round. $playInExists = !empty($this->bracket[0]) ? true : false; /* The y-size of the image must be calculated accordingly to the above description. Though, if a play-in round exists, then the play-in round is potentially the round which requires the most vertical space to draw. In this case we scale the image as if the play-in round was the first round. Due to the nature of the tournament bracket, this means that there are twice as many games in that round. */ $y = 2*$vertPad + ($playInExists ? $frGames*2 : $frGames) * 4*$fontHeight; /* The x-size of the image is proportional to the number of rounds in the tournament, where the proportionality constant is the length of a branch, $lineWidth, ie. the width of a round. Since the number of players in the first round is equal to 2^R, where R is a whole number, and denotes the number of rounds required in the tournament, then R = log(players, 2), where "players" also can be found by 2 * matches_in_first_round (2 players pr. match). Like above, if a play-in round exists the x-size of the image must be changed. In this case, we merely add the length of a branch to the total x-size, since all branches are equal in length. Besides that, we add another whole branch length for the Winner/Champion branch, which technically is not a part of the tournament bracket, but is shown anyway. */ $x = 2*$horizPad + (log($frGames*2, 2) + ($playInExists ? 1 : 0) + 1) * $lineWidth; return array('x' => $x, 'y' => $y); } private function getStrLen() { /* Returns the length of longest string used in either rounds. This is done by looking in both play-in round and first round, since all competitors are to be found there. */ $len = 0; foreach (array_merge(array_key_exists(0, $this->bracket) ? $this->bracket[0] : array(), $this->bracket[1]) as $m) { if (($newlen = strlen($m['c1'])) > $len) $len = $newlen; if (($newlen = strlen($m['c2'])) > $len) $len = $newlen; } foreach ($this->roundsInfo as $arr) { if (($newlen = strlen($arr[0])) > $len) $len = $newlen; } return $len; } } ?> What do I need to do in order to use the libssh2 library? I want to get the ibase_blob_echo function and I was told I need to uncomment the extension=php_interbase.dll in my php.ini. So I did and now I get the message: Unable to Load Dynamic Library in a pop-up window. I'm lost and don't know how to solve this Hi, I would like my users to create and save forms via mysql. They should be able to choose what field they want to use, and other users should be able to fill the forms into mysql. Any ideas on how to accomplish this? I'm trying to write a script that will copy images from one website (a supplier, in this case puma) and save them to the dealer's web server. I have already done this for other supplier's websites but puma uses png's instead of jpeg's and I believe that is what is causing my issues: The original image looks like this: The copied image some odd colors in the background like this: Here is the code: Code: [Select] $puma_image = "http://www.pumab2b.com/_static/images/styleColors/1234560002/" . str_replace(" ", "", $Item_Num) . "_1.png"; $image = imagecreatefrompng($puma_image); if ($image) { //Save image to Soccer Etc server (images folder): if (imagepng($image, "prod_images/" . $cur_Item['Item_Num'] . ".png", 0)) { //DO some other stuff here } } I just noticed after posting the original image on this forum, that it is actually transparent. I'm guessing this has something to do with my problems? GD Library Pattern Background ? Hi all I have a simple page here that uses the GD Library to display text in a selected font and size etc. http://www.ttmt.org.uk/forum/ At moment the stripped background goes from the code. Is there a way to have an image as the background instead of the stripped background. PHP code Code: [Select] <?php header('Content-Type: image/png'); $im = imagecreatetruecolor(900, 215); $w = imagecolorallocate($im, 255, 255, 255); $c = imagecolorallocate($im, 220, 220, 220); $black = imagecolorallocatealpha($im, 0, 0, 0, 20); $style = array($w,$w,$w,$c,$c,$c); ImageSetStyle($im, $style); ImageLine($image, 100, 0, 50, 50, IMG_COLOR_STYLED); imagefilledrectangle($im, 0, 0, 900, 214, IMG_COLOR_STYLED); $text = $_GET['text']; $textSize = $_GET['size']; $font = $_GET['font']; imagefttext($im, $textSize, 0, 15, 165, $black, $font, $text); imagepng($im); imagedestroy($im); ?> Hello everyone, What is the best way to take HTML formatted text and overlay it on a image (presumably using php's GD functions)? Unfortunately, HTML tags are ignored and any kind of code is treated as plaintext by imagefttext(). However, I need this HTML DIV box pasted onto an image and I intend to get it done. To make things slightly worst, this is a dynamic, PHP generated DIV box. I had an idea of utilizing some kind of buffering to generate my DIV box, convert that DIV box to an image and finally paste it onto my image using the GD library. If that sounds like a reasonable idea, can someone please help me get started? Thanks in advance, guys! hi, i'm using the fpdf library to generate PDF's from form input. It all worked well on my local host, but now that i have transferred to a web server it displays the following error when trying to generate a PDF. Warning: require(/fpdf16/fpdf.php) [function.require]: failed to open stream: No such file or directory in /home/ddgq0o2n/public_html/quote_builder/pdf.php on line 2 Fatal error: require() [function.require]: Failed opening required '/fpdf16/fpdf.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/ddgq0o2n/public_html/quote_builder/pdf.php on line 2 i have searched for "include_path", but can't find it anywhere. i'm thinking it's a server problem, where the library may not be compatible or something needs to be switched on, as it worked fine on my local host. any help and suggestions welcome thanks. I am trying to create a basic image with GD library, but my browser says that the image cannot be displayed because it contains errors... I have no idea why. Here's my code: Code: [Select] switch($_GET['case']){ case "progressbar": header('Content-Type: image/jpeg'); $barWidth = 6; $barHeight = 14; $barPadding = 2; $imageWidth = ($barWidth * 10) + (10 * $barPadding); $imageHeight = ($barHeight + ($barPadding * 2)); $img = @imagecreate($imageWidth, $imageHeight); $imgBorder = imagecolorallocate($img, 0, 0, 0); //imagefilledrectangle($img, 1, $imageHeight -1, $imageWidth - 1, $imageHeight - 1, $imgBorder); $output = "Hello, world!"; imagestring($img, 1, 4, 4, $output, $imgBorder); imagejpeg($img); imagedestroy($img); break; } I have a file called image.php that i use to create images and I use the URL image.php?case=progressbar. Font size GD Library Hi All I'm trying to create a font tester - http://www.ttmt.org.uk/fonts/index.php (this demo doesn't use the font I'm using.). I'm using the GD library to create images of the text. I'm not happy with the quality of the fonts at small sizes. I've tried everything to fix it but nothing is working. One suggestion I had was to create the fonts larger then reduce the size of the image. Can anyone offer any advise how I might do this? Code: [Select] <?php header('Content-Type: image/png'); $im = imagecreatetruecolor(1000, 200); $gray = imagecolorallocate($im, 240, 240, 240); $black = imagecolorallocate($im, 0, 0, 0); imagefilledrectangle($im, 0, 0, 1000, 199, $gray); $text = $_GET['text']; $textSize = $_GET['size']; $font = $_GET['font']; imagefttext($im, $textSize, 0, 15, 160, $black, $font, $text); imagepng($im); imagedestroy($im); ?> Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>untitled</title> <style type="text/css"> *{margin:0;padding:0;} #wrap{margin:20px 0 0 20px;} h1{margin:0px 0 20px 0;clear:both;} h2{font-size:1.1em;margin:15px 0 5px 0;} #top{padding:0 0 20px 0;} form{margin:0 0 20px 0;} </style> </head> <body> <div id="wrap"> <form action="index.php" method="post"> <!--<input type="text" name="text" value="<?php echo $_POST['text'];?>" />--> <select name="text" > <option value="<?php echo $_POST['text'];?>">Text</option> <option value="ABCDEFGHIJKLMNOPQRSTUVWXYZ">ABCDEFGHIJKLMNOPQRSTUVWXYZ</option> <option value="abcdefghijklmnopqrstuvwxyz">abcdefghijklmnopqrstuvwxyz</option> <option value="0123456789">0123456789</option> </select> <select name="size"> <option value="<?php echo $_POST['size'];?>">Size</option> <option value="10">10</option> <option value="12">12</option> <option value="14">14</option> <option value="18">18</option> <option value="24">24</option> <option value="30">30</option> <option value="38">38</option> <option value="42">42</option> <option value="50">50</option> <option value="60">60</option> <option value="80">80</option> <option value="100">100</option> </select> <input type="submit" name="submit" value="Set →" /> </form> <div id="top"> <?php $theFont="corbelb.ttf"; if(!empty($_POST['submit'])){ $myText = $_POST['text']; $mySize = $_POST['size']; echo '<img src="imageftt.php?text='.$myText.'&size='.$mySize.'&font='.$theFont.'">'; }else{ $myText = "Handgloves"; $mySize = 24; echo '<img src="imageftt.php?text='.$myText.'&size='.$mySize.'&font='.$theFont.'">'; } ?> </div> </div> </body> </html> Hello, what's the correct use of GD library to compress JPG images please? I am using this upload script with TinyMCE. See below : I have this snippet but it doesn't compress the image: // Accept upload if there was no origin, or if it is an accepted origin // If image is JPEG compress with GD library $filetowrite = $imageFolder . $temp['name']; if (in_array(strtolower(pathinfo($temp['name'], PATHINFO_EXTENSION)), array("jpg", "jpeg"))) { imagejpeg($temp['tmp_name'], $filetowrite, 75); } else { move_uploaded_file($temp['tmp_name'], $filetowrite); } <?php $accepted_origins = array("http://localhost", "http://127.0.0.1", "http://192.168.1.1", "http://example.com"); $month = strtolower(date('M')); $year = date('Y'); $newspath = "img/news/"; if (!is_dir("$newspath/$year/$month")) { mkdir("$newspath/$year/$month", 0777, true); } $imageFolder = "$newspath/$year/$month/"; reset ($_FILES); $temp = current($_FILES); if (is_uploaded_file($temp['tmp_name'])){ if (isset($_SERVER['HTTP_ORIGIN'])) { // same-origin requests won't set an origin. If the origin is set, it must be valid. if (in_array($_SERVER['HTTP_ORIGIN'], $accepted_origins)) { header('Access-Control-Allow-Origin: ' . $_SERVER['HTTP_ORIGIN']); } else { header("HTTP/1.1 403 Origin Denied"); return; } } /* If your script needs to receive cookies, set images_upload_credentials : true in the configuration and enable the following two headers. */ // header('Access-Control-Allow-Credentials: true'); // header('P3P: CP="There is no P3P policy."'); // Sanitize input if (preg_match("/([^\w\s\d\-_~,;:\[\]\(\).])|([\.]{2,})/", $temp['name'])) { header("HTTP/1.1 400 Invalid file name."); return; } // Verify extension if (!in_array(strtolower(pathinfo($temp['name'], PATHINFO_EXTENSION)), array("gif", "jpg", "jpeg", "png"))) { header("HTTP/1.1 400 Invalid extension."); return; } // Accept upload if there was no origin, or if it is an accepted origin // If image is JPEG compress with GD library $filetowrite = $imageFolder . $temp['name']; if (in_array(strtolower(pathinfo($temp['name'], PATHINFO_EXTENSION)), array("jpg", "jpeg"))) { imagejpeg($temp['tmp_name'], $filetowrite, 75); } else { move_uploaded_file($temp['tmp_name'], $filetowrite); } // Respond to the successful upload with JSON. // Use a location key to specify the path to the saved image resource. // { location : '/your/uploaded/image/file'} // echo json_encode(array('location' => $filetowrite)); $passpath = $year.'/'.$month.'/'.$temp['name']; echo json_encode(array('location' => $passpath)); } else { // Notify editor that the upload failed header("HTTP/1.1 500 Server Error"); } ?>
I want to create a media library in the CMS, similar to how it is in WordPress but custom-coded in PHP on my own site. Can this be done simply with a database connection or will the images need to be uploaded to a server? Bit confused as to how it works and which is the best way to go about it. Thanks for any help. Edited January 12 by Richie1209Suppose you have a ENORMOUS library class where you have collected - perhaps - validation functions. Suppose you also have a small php script that you wish to use one of these validation functions in. So, you include the class. Is there a lot of "overhead" involved in including a huge class of which you use only one function? Thats my question. Its a good practice? Gives error in a php file without html, for example? About the library, i have a 1500lines single php file and i modualritizing it. There is any advice in general when creating a php library?
How to implement the library
here's my code <?php include("../incs/config.php"); $result = mysqli_query($link, "SELECT * FROM press ORDER BY press_date DESC"); $result2 = mysqli_query($link, "SELECT * FROM event ORDER BY event_date DESC"); $result3 = mysqli_query($link, "SELECT * FROM galleries ORDER BY gallery_id DESC"); if (!isset($_COOKIE['user'])) { die("Identifiant invalide"); } ?> <!DOCTYPE html><html> <head><meta charset='UTF-8'> <meta name="robots" content="noindex"> </head> <html> <head> <link rel="stylesheet" href="../css/bootstrap.min.css"> <link rel="stylesheet" href="../css/jquery-ui.css"> <link href="../stylesheets/style.css" rel="stylesheet"> <link href="stylesheets/style.css" rel="stylesheet"> <script src="../js/jquery-migrate.min.js"></script> <script src="../js/jquery.min.js"></script> <script src="../js/jquery.ui.js"></script> <script src="../js/bootstrap.min.js"></script> <script src="../js/tinymce/js/tinymce/tinymce.min.js"></script> </head> <body> <!-- header --> <header> <!-- nav --> <nav class="navbar navbar-default"> <div class="container"> <div class="navbar-header"> <a class="navbar-brand" href="../index.php"><img src="../images/logo.png" alt="Louise Groux"></a> </div><!-- / navbar-header --> <div> <ul class="nav nav-pills navbar-nav" style="font-weight:bold; padding-left:25px;"> <li class="active"><a href="#presse-2" data-toggle="pill"><i class="fa fa-home"></i> Presse </a></li> <li><a href="#evenements-2" data-toggle="pill"><i class="fa fa-comments"></i> Événements </a></li> <li><a href="#galerie-2" data-toggle="pill"><i class="fa fa-cloud"></i> Galerie</a></li> </ul> </div><!--/ nav-collapse --> </div><!-- / container --> </nav> <!-- / nav --> </header> <!-- / header --> <!--<div class="container-fluid"> <div class="row"> <a class="navbar-brand" href="../index.php"><img src="../images/logo.png" alt="logo" width="50" height="50"></a> </div> </div> --> <div class="container content-sm"> <!-- Tab v3 --> <div class="row tab-v3"> <div class="col-sm-9"> <div class="tab-content"> <div class="tab-pane fade in active" id="presse-2"> <div class="container col-md-12""> <h1>Presse</h1> <div style="text-align:center;margin:40px;">Veuillez utiliser la page pour mettre à jour, ajouter et supprimer des articles de presse. Faites glisser pour changer l'ordre et n'oubliez pas de sauvegarder une fois terminé !</div> <ul class="list-unstyled"> <li class="panel panel-info"> <div class="panel-heading"> <h5></h5> </div> <div class="panel-body"> <form action="presse/add.php" method="post" name="form1" enctype="multipart/form-data"> <div class="form-horizontal"> <div class="form-group"> <label class="control-label col-sm-2" for="title">Tit </label> <div class="col-sm-10"> <input type="text" class="form-control" name='title' id="title" > </div> </div> </div> <div class="form-horizontal"> <div class="form-group"> <label class="control-label col-sm-2" for="sub_title">Sous-tit </label> <div class="col-sm-10"> <input type="text" class="form-control" name='sub_title' id="sub_title"> </div> </div> </div> <div class="form-horizontal"> <div class="form-group"> <label class="control-label col-sm-2" for="press_date">Date (invisible, pour l'ordre de la liste):</label> <div class="col-sm-10"> <input type="text" class="form-control datepicker" name='press_date' id="press_date"> </div> </div> </div> <div class="form-horizontal"> <div class="form-group"> <label class="control-label col-sm-2" for="type">Gen </label> <div class="col-sm-10"> <input type="text" class="form-control" name='type' id="type" > </div> </div> </div> <div class="form-horizontal"> <div class="form-group"> <label class="control-label col-sm-2" for="type">Lien:</label> <div class="col-sm-10"> <input type="text" class="form-control" name='link' id="link"> </div> </div> </div> <div class="form-horizontal"> <div class="form-group"> <label class="control-label col-sm-2" for="type">Image (150px x 150px): </label> <div class="col-sm-10"> <input class="input-group" type="file" name="image"/> </div> </div> </div> <input type="submit" name="Submit" class="btn btn-louisegroux pull-right" value="Ajouter"></button> </form> </div> </li> </ul> <?php if ($result->num_rows > 0) { //<button class="save btn btn-louisegroux">Sauvegarder l'ordre des éléments</button> } ?> <div id="accordion-resizer" class="ui-widget-content"> <div id="accordion"> <ul id="draggablePanelList" class="sortable press_sort list-unstyled"> <?php while ($res = mysqli_fetch_array($result)) { $title = $res['title']; $sub_title = $res['sub_title']; $press_date = $res['press_date']; $type = $res['type']; $news_link = $res['link']; $image = $res['image']; $id = $res['id']; $title = stripslashes($title); $sub_title = stripslashes($sub_title); ?> <li name='item' id='item-<?php echo "$id"; ?>' class="panel panel-info""> <div class="panel-heading"> <h3 class="panel-title pull-left"> <?php echo "$title"; ?><span>, </span><?php echo "$sub_title"; ?> </h3> <a href="presse/delete.php?id=<?php echo "$id"; ?>"; ><button class="btn btn-danger clickable pointer pull-right" data-effect="remove"><span class="glyphicon glyphicon-remove"></span></button></a> <div class="clearfix"></div> </div> <div class="panel-body"> <form name="form1" action=presse/edit.php?id="<?php echo "$id"; ?>" method="post" enctype="multipart/form-data"> <div class="col-md-3"> <div class="form-group"> <?php if ($image != "") { ?> <img src="../images/presse/<?php echo "$image"; ?>" class="img-responsive" style="max-height:150px; max-width:150px;"> <?php } ?> <div class="clearfix"></div> <input class="input-group" type="file" name="image"/> </div> </div> <div class="col-md-9"> <div class="form-horizontal"> <div class="form-group"> <label class="control-label col-sm-2" for="title">Tit </label> <div class="col-sm-10"> <input type="text" class="form-control" name='title' id="title" value="<?php echo "$title"; ?>"> </div> </div> </div> <div class="form-horizontal"> <div class="form-group"> <label class="control-label col-sm-2" for="title">Sous-tit </label> <div class="col-sm-10"> <input type="text" class="form-control" name='sub_title' id="sTitle" value="<?php echo "$sub_title"; ?>"> </div> </div> </div> <div class="form-horizontal"> <div class="form-group"> <label class="control-label col-sm-2" for="press_date">Date (invisible, pour l'ordre de la liste):</label> <div class="col-sm-10"> <input type="text" name="press_date" value="<?php echo "$press_date"; ?>"> </div> </div> </div> <div class="form-horizontal"> <div class="form-group"> <label class="control-label col-sm-2" for="type">Gen </label> <div class="col-sm-10"> <input type="text" class="form-control" name='type' id="type" value="<?php echo "$type"; ?>"> </div> </div> </div> <div class="form-horizontal"> <div class="form-group"> <label class="control-label col-sm-2" for="type">Lien:</label> <div class="col-sm-10"> <input type="text" class="form-control" name='link' id="link" value="<?php echo "$news_link"; ?>"> </div> </div> </div> </div> <input type="hidden" name="id" value="<?php echo "$id"; ?>"> <input type="hidden" name="old_image" value="<?php echo "$image"; ?>"> <button type="submit" name="update" class="btn btn-louisegroux pull-right">Mettre à jour</button> </form> </div> </li> <?php } ?> Edited October 16, 2019 by samplephp Hello, can any1 show me how to insert the following in db Code: [Select] <?php include('dbconnect.php'); include('simple_html_dom.php'); $html = file_get_dom('test3.php'); foreach($html->find('h2') as $heading) { //echo $heading; foreach ($heading->find('a') as $link) { $item_title = md5($link); echo $link."<br/>"; $sql = "INSERT INTO articles(article_id, article_link) VALUES($item_title, $link)"; $result = mysql_query($sql); } } ?> what i want to do is insert every link in the db, but this is not working. The output is ok but the insert doesnt work. Any help please?? Hello, I have this script running: Code: [Select] <?php //include("include/session.php"); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Add an Image to Gallery</title> <link href="../../include/stylee.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="wrap"> <div id="content"> <form enctype="multipart/form-data" action="<? $_SERVER['PHP_SELF'] ?>" method="post"> <fieldset title="Add Images and Descriptions"> <legend>Add Images and Descriptions</legend> <p> Choose a file to upload: <br /> <input name="image" type="file" /> </p> <p>Give the Image a Short Description<br /> <input name="ushortdesc" type="text" size="60" maxlength="75" /> </p> <p>Give the Image a Long Description<br /> <textarea name="ulongdesc" cols="60" rows="10"></textarea> </p> <p>Where does the Image Link to?<br /> <input name="uimglink" type="text" value="http://www.yoursite.com/yourstore/or..." size="60" /> </p> <p> <input type="submit" name="upload" value="Upload" /> </p> </fieldset> </form> </div> <div id="report"> <?php //function createThumbs( $pathToImages, $pathToThumbs, $thumbWidth ) //{ // // open the directory // $dir = opendir( $pathToImages ); // // // loop through it, looking for any/all JPG files: // while (false !== ($fname = readdir( $dir ))) { // // parse path for the extension // $info = pathinfo($pathToImages . $fname); // // continue only if this is a JPEG image // if ( strtolower($info['extension']) == 'jpg' ) // { // echo "Creating thumbnail for {$fname} <br />"; // // // load image and get image size // $img = imagecreatefromjpeg( "{$pathToImages}{$fname}" ); // $width = imagesx( $img ); // $height = imagesy( $img ); // // // calculate thumbnail size // $new_width = $thumbWidth; // $new_height = floor( $height * ( $thumbWidth / $width ) ); // // // create a new temporary image // $tmp_img = imagecreatetruecolor( $new_width, $new_height ); // // // copy and resize old image into new image - for gd-1 version // //imagecopyresized( $tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height ); // //randys alteration for gd-2 version // imagecopyresampled( $tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height ); // // // save thumbnail into a file // imagejpeg( $tmp_img, "{$pathToThumbs}{$fname}" ); // } // } // // close the directory // closedir( $dir ); //} // // call createThumb function and pass to it as parameters the path //// to the directory that contains images, the path to the directory //// in which thumbnails will be placed and the thumbnail's width. //// We are assuming that the path will be a relative path working //// both in the filesystem, and through the web for links //createThumbs("images/","images/thumbs/",100); //echo "<h2>All Done!</h2>"; if(isset($_POST['upload'])) { $size = 50; // the thumbnail height $filedir = 'images/'; // the directory for the original image $thumbdir = 'thumbs/'; // the directory for the thumbnail image $prefix = 'thumb_'; // the prefix to be added to the original name $maxfile = '2100000'; $mode = '0666'; $userfile_name = $_FILES['image']['name']; $userfile_tmp = $_FILES['image']['tmp_name']; $userfile_size = $_FILES['image']['size']; $userfile_type = $_FILES['image']['type']; if (isset($_FILES['image']['name'])) { $uimg = $filedir.$userfile_name; $uimg_thumb = $thumbdir.$prefix.$userfile_name; move_uploaded_file($userfile_tmp, $uimg); chmod ($uimg, octdec($mode)); $sizes = getimagesize($uimg); $aspect_ratio = $sizes[0]/$sizes[0]; if ($sizes[0] <= $size) { $new_width = $sizes[0]; $new_height = $sizes[0]; }else{ $new_height = $size; $new_width = abs($new_height/$aspect_ratio); } $destimg=ImageCreateTrueColor($new_width,$new_height) or die('Problem In Creating image'); $srcimg=ImageCreateFromJPEG($uimg) or die('Problem In opening Source Image'); if(function_exists('imagecopyresampled')) { imagecopyresampled($destimg,$srcimg,0,0,0,0,$new_width,$new_height,ImageSX($srcimg),ImageSY($srcimg)) or die('Problem In resizing'); }else{ Imagecopyresized($destimg,$srcimg,0,0,0,0,$new_width,$new_height,ImageSX($srcimg),ImageSY($srcimg)) or die('Problem In resizing'); } ImageJPEG($destimg,$uimg_thumb,90) or die('Problem In saving'); imagedestroy($destimg); } echo ' <a href="'.$uimg.'"> <img src="'.$uimg_thumb.'" width="'.$new_width.'" heigt="'.$new_height.'"> </a>'; } ?> </div> </body> </html> Works great, except when I upload a 400kb or larger file... Is there some kind of limit to the ability of the GD library? Anyone have a work around? Thanks! Hey guys, I'm working on a tool to add to a site that will search by title, author, keyword (3 radio buttons), category(drop-down list),as in a library. I'm working with dreamweaver CS5 with php. I was trying to create recordset with viarables (that display ex. $_POST['category']) and use an if function (if (radioButton1 == checked) { return something } and connect this all to dynamic table. Getting so many errors, I'm asking you for advice how I can do this ? Could you please explain it to me as simple as possible, as I just started using dreamweaver with php. Thanks ! |