Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Image Upload Issues

copying to the wrong folder

3:17 am on Mar 14, 2007 (gmt 0)

New User

10+ Year Member

joined:Oct 21, 2006
votes: 0


I have an image upload script that is in the root folder. I want the script to copy images to "/photos/image.jpg" -- "photos" is a directory that I have in the root. The problem is that I am using the PHP function imagecopyresampled but it doesn't appear to have a place to copy the image to a specified location. If you have any ideas, let me know!


12:45 pm on Mar 14, 2007 (gmt 0)

Senior Member

WebmasterWorld Senior Member eelixduppy is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Nov 12, 2005
votes: 0

Are you getting any errors from the script? If so, could you please post the error with the corresponding line.

It seems that you aren't using imagecopyresampled [us2.php.net] correctly. you must have an image link resource as the destination, and not a specific file. Look at some of the examples at the documentation to get a better understanding. I believe this is where your error lies.

Good luck! :)

9:41 pm on Mar 14, 2007 (gmt 0)

New User

10+ Year Member

joined:Oct 21, 2006
votes: 0

Thanks for posting, but the problem is that it is not throwing an error. It simply puts the file into the root folder. Here is the code:

$valid_file = $_FILES['profile_image']['tmp_name'];
$file_type = $_FILES['profile_image']['type'];
$file_size = $_FILES['profile_image']['size'];
if(validateFileType($file_type) === true && validateFileSize($file_size) === true && fileExists($valid_file) === true) {
$file_ext = returnExtension($file_type);
$file_name = md5($uid).$file_ext;
$thumb_name = md5($uid).'-thumb'.$file_ext;
$file_location = "/".$file_name;
$thumb_location = "/".$thumb_name;
if($user_row['image'] == $file_name) {
if($user_row['thumbnail'] == $thumb_name) {
$original_size = getimagesize($valid_file);
$original_width = $original_size[0];
$original_height = $original_size[1];
$new_height = resizeImage($valid_file, "height");
$new_width = resizeImage($valid_file, "width");
$thumb_height = createThumbnail($valid_file, "height");
$thumb_width = createThumbnail($valid_file, "width");
$new_image = imagecreatetruecolor($new_width, $new_height);
$thumb_image = imagecreatetruecolor($thumb_width, $thumb_height);
$src_image = imagecreatefromjpeg($valid_file);
imagecopyresampled($new_image, $src_image, 0, 0, 0, 0, $new_width, $new_height, $original_width, $original_height);
imagecopyresampled($thumb_image, $src_image, 0, 0, 0, 0, $thumb_width, $thumb_height, $original_width, $original_height);
imagejpeg($new_image, $file_name);
imagejpeg($thumb_image, $thumb_name);
$upload_query = "UPDATE user SET image = '$file_name', thumbnail = '$thumb_name' WHERE uid = '$uid'";
$upload_result = mysql_query($upload_query) or die(mysql_error());
header("Location: /editprofile.php");

all of the "validate" functions are working properly as well as the functions that create thumbnails (gets the size) and resize images.

I just don't know how to get it into the "photos" folder.


10:12 pm on Mar 14, 2007 (gmt 0)

Junior Member

10+ Year Member

joined:Aug 25, 2003
votes: 0

You could always try the copy() function altho unsure of its applicability in this situation:

$imageDIR = 'new/location/of/image/including/final/slash/';
$_FILES['filevar']['name'] = 'new name for picture.extension';

copy($_FILES['filevar']['tmp_name'], $imageDIR.$_FILES['filevar']['name'])or die("Could not copy");

I use this in conjunction with the script located below and works a treat.

Alternatively you could use this, which ive found useful in the past: phpThumbnailer

I take it you will have looked on php.net for any related information to the functions you are trying to use.

[edited by: eelixduppy at 10:15 pm (utc) on Mar. 14, 2007]
[edit reason] no URLs, please - See TOS [/edit]


Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members