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
https://forums.phpfreaks.com/topic/106825-upload-not-working/
Share on other sites

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.