Jump to content

upload not working???


jasonhardwick

Recommended Posts

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

 

<?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); 
?>

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.