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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.