jasonhardwick Posted May 22, 2008 Share Posted May 22, 2008 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 More sharing options...
jasonhardwick Posted May 22, 2008 Author Share Posted May 22, 2008 I feel like my problem is on this line but not sure how to fix it "$ext = findexts ($_FILES[$filename1]['name']) ;" anything? Link to comment https://forums.phpfreaks.com/topic/106825-upload-not-working/#findComment-547669 Share on other sites More sharing options...
jasonhardwick Posted May 23, 2008 Author Share Posted May 23, 2008 is this really that hard of a function that no one has any suggestions... maybe there is a better function to use.... anything??? Link to comment https://forums.phpfreaks.com/topic/106825-upload-not-working/#findComment-548045 Share on other sites More sharing options...
Dathremar Posted May 23, 2008 Share Posted May 23, 2008 I usually use the explode function to get me extension from a file name. Try something like $resault = explode($_FILES[$filename1]['name'], '.'); $ext = $resault[1]; Hope it helps Link to comment https://forums.phpfreaks.com/topic/106825-upload-not-working/#findComment-548056 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.