Jump to content

PHP/Imagemagick upload and file save help please :D


shmegeger

Recommended Posts

Hi,

 

Very new to PHP and am enjoying learning the ins and outs etc, but while creating my mam a website, ive ran into a problem while uploading, resizing and saving the file to my web host. Initially i used imagecreatefromjpeg, but this was taking too much memory up, so opted to use imagemagick. All of the features work apart from the file getting saved to the uploads directory on my web space. They always get saved to the root. If someone could help i would be very grateful. The code ive got currently is:

 

<?php

 

// If the form has been submitted do this

if(isset($_POST['submit'])) { 

 

// Temporary upload image name

$original_image = $_FILES['photo']['tmp_name']; 

 

// Get the image dimensions

$size=GetImageSize( $original_image );

 

// Name to save the image as - in this case the same as the original

$new_image = $_FILES['photo']['name'];

 

// Maximum image width

$max_width = "600";

 

// Maximum image height

$max_height = "300";

 

// Resize the image and save

exec("convert -size {$size[0]}x{$size[1]} $original_image -thumbnail $max_widthx$max_height $new_image");

 

echo "File uploaded<br>";

 

echo "<img src=\"".$new_image."\">";

}

 

?>

 

Hopefully someone could help :D

 

Many thanks,

 

Matk.

Hi, thanks so much, ive been trying so long to do this haha. What a total noob i am! Added the following code and worked like a dream.

 

$imagename = $_FILES['photo']['name'];

 

// Name to save the image as - in this case the same as the original

$new_image = "uploads/".$imagename;

 

Again, thankyou so much for this.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.