Hey guys !
On my site, if a user uploads a pic it's stored in user_pics/username_1.jpg. I changed the upload.php file by adding a fucntion to resize the pic before it stores it but it doesn't work. I have no errors but the pic just isn't being resized, it displays as normal. Any ideeas on how to fix it ?
Here's the code of the function:
// resize function
function resize_jpg($nume,$picture_width,$picture_height){
$nume="user_pic/".$nume;
$thumb = imagecreate ($picture_width, $picture_height);
$image = ImageCreateFromJpeg($nume);
$imagedata = getimagesize($nume);
imagecopyresized ($thumb, $image, 0, 0, 0, 0, $picture_width, $picture_height, $imagedata[0], $imagedata[1]);
imagejpeg($thumb, $nume);
}
This is the code of the upload.php file:
db_connect($dbserver,$dbuser,$dbpass,$dbname);
$path=pathinfo(realpath("upload_file.php"));
if (isset($fisier))
{
$fisier=urldecode($fisier);
//$location=$path["dirname"]."\user_pic\ ".gaseste_user_by_id($usernick).strstr($fisier_name,'.');
//$type poate fi image sau audio
if (substr($fisier_type,0,5)=="image")
{
$location=$path["dirname"]."/user_pic/ ";
if ($fisier_size<=$size_pic)// marimea maxima admisa
{
$sql="select count(*) from pictures where user_id=$usernick";
$result=mysql_query($sql);
$num=mysql_numrows($result);
$nr=mysql_result($result,0,"count(*)");
if ($nr>=$nr_max_pic)
{
echo $nr_max_poze;
?>
<script>
window.location="my_pictures.php"
</script>
<?
}
else
{
if ($nr==0)
{$nr=1;}
$nume=strtolower(gaseste_user_by_id($usernick)."_".$nr.strstr($fisier_name,'.'));
$nume=ltrim($nume);
$nume=rtrim($nume);
$location.=$nume;
unlink($location);
resize_jpg ($nume,50,50);
$sql="insert into pictures values (' ',$usernick,'$nume')" ;
$result=mysql_query($sql);
if (!$result)
{
echo("CHECK HERE: user_pic/".$nume." UNTIL HERE");
echo $sql_error;
}
;
$reusit=copy ($fisier,$location);
// $reusit=move_uploaded_file ($fisier,strtolower($location));
if ($reusit==1)
{echo $upload_reusit;
echo("CHECK HERE: user_pic/".$nume." UNTIL HERE");
?>
<script>
// window.location="my_pictures.php"
</script>
<?
}
else{
echo $upload_nereusit;
?>
Any help is appreciated, I ran out of ideeas. Thanks in advance !