Note that there are some explanatory texts on larger screens.

plurals
  1. POphp picture resize not working on image upload
    primarykey
    data
    text
    <p>I'm trying to resize an image that's being uploaded on my php form. The picture is being saved but not resizing. Basically, everything is working fine except for the resizing of the image part. I put my code below.</p> <p>html form with php for re sizing</p> <pre><code>&lt;?php include "base.php"; ?&gt; &lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;Submit an Album&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;?php if( isset($_POST['submit']) ) { include('SimpleImage.php'); $image = new SimpleImage(); $image-&gt;load($_FILES['albumCover']['tmp_name']); $image-&gt;resize(150,150); $image-&gt;output(); } else { ?&gt; &lt;table&gt; &lt;tr&gt; &lt;td align="center"&gt;Submit an Album&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;table&gt; &lt;form enctype="multipart/form-data" action="submitAlbumForm.php" method="post"&gt; &lt;tr&gt; &lt;td&gt;Artist Name&lt;/td&gt; &lt;td&gt;&lt;input type="text" name="artistName" size="20"&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Album Name&lt;/td&gt; &lt;td&gt;&lt;input type="text" name="albumName" size="20"&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;tr&gt; &lt;td&gt;Release Date&lt;/td&gt; &lt;td&gt;&lt;input type="text" name="releaseDate" size="20"&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;tr&gt; &lt;td&gt;Leak Date&lt;/td&gt; &lt;td&gt;&lt;input type="text" name="leakDate" size="20"&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;tr&gt; &lt;td&gt;Where It Leaked&lt;/td&gt; &lt;td&gt;&lt;input type="text" name="whereItLeaked" size="20"&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;tr&gt; &lt;td&gt;Album Cover&lt;/td&gt; &lt;td&gt;&lt;input type="file" name="albumCover"&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;/td&gt; &lt;td align="right"&gt;&lt;input type="submit" name="submit" value="Add"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/form&gt; &lt;/table&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;?php } ?&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>submitAlbumForm.php, the php form for uploading form info to database</p> <pre><code>&lt;?php include "base.php"; //Setting up images directory $target = "images/"; $target = $target . basename( $_FILES['albumCover']['name']); $albumCover=($_FILES['albumCover']['name']); //inserting data order $order = "INSERT INTO albums (artistName, albumName, releaseDate, leakDate, whereItLeaked, albumCover) VALUES ('$_POST[artistName]', '$_POST[albumName]', '$_POST[releaseDate]', '$_POST[leakDate]', '$_POST[whereItLeaked]', '{$_FILES['albumCover']['name']}')"; //Writes image to database mysql_query("INSERT INTO `albums` VALUES ('albumCover')") ; if(move_uploaded_file($_FILES['albumCover']['tmp_name'], $target)) { //Tells you if its all ok echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory"; } else { //Gives an error if its not echo "Sorry, there was a problem uploading your file."; } //declare in the order variable $result = mysql_query($order); //order executes if($result){ echo("&lt;br&gt;Thank you for submitting!"); } else{ echo("&lt;br&gt;Sorry, something went wrong! Please try again!"); } ?&gt; </code></pre> <p>SimpleImage.php, the script i'm using for resizing the image-</p> <pre><code>&lt;?php /* * File: SimpleImage.php * Author: Simon Jarvis * Copyright: 2006 Simon Jarvis * Date: 08/11/06 * Link: http://www.white-hat-web-design.co.uk/articles/php-image-resizing.php * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details: * http://www.gnu.org/licenses/gpl.html * */ class SimpleImage { var $image; var $image_type; function load($filename) { $image_info = getimagesize($filename); $this-&gt;image_type = $image_info[2]; if( $this-&gt;image_type == IMAGETYPE_JPEG ) { $this-&gt;image = imagecreatefromjpeg($filename); } elseif( $this-&gt;image_type == IMAGETYPE_GIF ) { $this-&gt;image = imagecreatefromgif($filename); } elseif( $this-&gt;image_type == IMAGETYPE_PNG ) { $this-&gt;image = imagecreatefrompng($filename); } } function save($filename, $image_type=IMAGETYPE_JPEG, $compression=75, $permissions=null) { if( $image_type == IMAGETYPE_JPEG ) { imagejpeg($this-&gt;image,$filename,$compression); } elseif( $image_type == IMAGETYPE_GIF ) { imagegif($this-&gt;image,$filename); } elseif( $image_type == IMAGETYPE_PNG ) { imagepng($this-&gt;image,$filename); } if( $permissions != null) { chmod($filename,$permissions); } } function output($image_type=IMAGETYPE_JPEG) { if( $image_type == IMAGETYPE_JPEG ) { imagejpeg($this-&gt;image); } elseif( $image_type == IMAGETYPE_GIF ) { imagegif($this-&gt;image); } elseif( $image_type == IMAGETYPE_PNG ) { imagepng($this-&gt;image); } } function getWidth() { return imagesx($this-&gt;image); } function getHeight() { return imagesy($this-&gt;image); } function resizeToHeight($height) { $ratio = $height / $this-&gt;getHeight(); $width = $this-&gt;getWidth() * $ratio; $this-&gt;resize($width,$height); } function resizeToWidth($width) { $ratio = $width / $this-&gt;getWidth(); $height = $this-&gt;getheight() * $ratio; $this-&gt;resize($width,$height); } function scale($scale) { $width = $this-&gt;getWidth() * $scale/100; $height = $this-&gt;getheight() * $scale/100; $this-&gt;resize($width,$height); } function resize($width,$height) { $new_image = imagecreatetruecolor($width, $height); imagecopyresampled($new_image, $this-&gt;image, 0, 0, 0, 0, $width, $height, $this-&gt;getWidth(), $this-&gt;getHeight()); $this-&gt;image = $new_image; } } ?&gt; </code></pre> <p>I know I have a lot of security holes right now, and will be working on those soon! Thanks guys!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload