Upload not working...
Posted: Thu May 22, 2008 3:14 pm
So I've got this code that takes an image that is uploaded resizes it and renames it... but it doesnt work properly i know i'm missing something just dont know what...
Code: Select all
<?php
include "config.php";
$user_image = $_FILES['user_image']['tmp_name'];
$filename1 = $_FILES['user_image']['name'];
function findexts ($filename)
{
$filename = strtolower($filename) ;
$exts = split("[/\\.]", $filename) ;
$n = count($exts)-1;
$exts = $exts[$n];
return $exts;
}
$src1 = imagecreatefromjpeg($user_image);
list($width1,$height1)=getimagesize($user_image);
$newwidth1=250;
$newheight1=($height1/$width1)*250;
$tmp1=imagecreatetruecolor($newwidth1,$newheight1);
imagecopyresampled($tmp1,$src1,0,0,0,0,$newwidth1,$newheight1,$width1,$height1);
$tbl_name="user";
$username=$_SESSION['username'];
$ext = findexts ($_FILES[$filename1]['name']) ;
$new_name = $username.".";
imagejpeg($tmp1,$target,100);
$target = "user_images/";
$target1 = $target . $new_name.$ext;
if(move_uploaded_file($_FILES[$filename1]['tmp_name'], $target1))
{
$sql=( "UPDATE $tbl_name SET user_image = '".$new_name.$ext."' WHERE uname='$username'");
$rows = mysql_query($sql);
echo "Your profile image has been sucessfully updated";
$id = mysql_insert_id();
echo $id;
}
else
{
echo "Sorry, there was a problem uploading your file.";
}
imagedestroy($src1);
imagedestroy($tmp1);
?>