Jump to content

PHP Image upload problem


buknoii

Recommended Posts

Hi there! I've been developing a simple website wherein users on my website can upload their picture, once it is uploaded it will be renamed according to time and its width resized to 470px.

 

I have been success working on it on my local computer but once I uploaded it on my webhosting service, the resizing script doesnt work.

 

Please check my code below

 


<?php
$userid=$_POST["userid"];

include("dbconnect.php");   

$result = mysql_query("select * from community_user_info  where user_xid='$userid' ") or
die (mysql_error());

while ($row = mysql_fetch_array($result))
	{
		echo $row["user_xid"];
		$user_id = $row["user_xid"];
		#echo "<br>-->".$user_id."<br>";
	}
mysql_free_result($result);
?>






<?php

$target_path = "photos/";

$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 


if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) 
	{
		echo "The file ".  basename( $_FILES['uploadedfile']['name']). " has been uploaded";
	} 

else

	{
		echo "There was an error uploading the file, please try again!";
	}

?>
<br><br>



<?php



?>




<Br><br>
<?
$newfilename= date(("ydjGHs"));
$oldWD = getcwd();
$path="photos";
chdir($path);
rename("".basename( $_FILES['uploadedfile']['name'])."","".$user_id."-".$newfilename.".jpg");
echo "<input type='text' value='".$user_id."-".$newfilename.".jpg"."'><br>";
chdir($oldWD);
?>
<br><br>

<?php

echo $photo =  $user_id."-".$newfilename.".jpg";

chmod("photos/".$photo."", 0755);



mysql_query("INSERT INTO community_user_photo (user_id,user_photo)  VALUES ('$user_id','$photo') ") 
or die(mysql_error());  


?>

<h2>photo added</h2>
<br><Br><Br><Br><Br>




<?php

// File and new size
$filename = "photos/".$photo;

//echo($filename);

// Get new sizes
list($width, $height) = getimagesize($filename);

//figure out height ratios

$newwidth = 470;
$newheight = ($newwidth/$width) * $height;

echo "new height -->".$newheight."<br>";
// Load
$thumb = imagecreatetruecolor($newwidth, $newheight);
$source = imagecreatefromjpeg($filename);

echo "thumb -->".$thumb."<br>";
echo "thumb -->".$source."<br>";

// resize
imagecopyresampled($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);

// Save the image as 'mynewpic.jpg'
imagejpeg($thumb, ''.$filename,85);


// Free up memory
imagedestroy($thumb);
?> 


 

Any help or tips would be appreciated.

Link to comment
Share on other sites

thanks for the reply.. i tried changing the path from photos/ to  var/www/html/community/photos but still no luck

i heard that i need to chech my gd library?? whats a gd library?

also what are the short tags that i used in my script? i just copied and paste some of this script so i really dont have idea what wrong with the script...

 

thanks

Link to comment
Share on other sites

i tried to check my hosting service and it produces this kind of output

 

 

Array ( [0] => libxml [1] => xml [2] => wddx [3] => tokenizer [4] => sysvshm [5] => sysvsem [6] => sysvmsg [7] => standard [8] => SimpleXML [9] => sockets [10] => SPL [11] => shmop [12] => session [13] => Reflection [14] => pspell [15] => posix [16] => pcntl [17] => mime_magic [18] => iconv [19] => hash [20] => gmp [21] => gettext [22] => ftp [23] => exif [24] => date [25] => curl [26] => ctype [27] => calendar [28] => bz2 [29] => zlib [30] => pcre [31] => openssl [32] => dbase [33] => gd [34] => imap [35] => ldap [36] => mbstring [37] => mysql [38] => mysqli [39] => PDO [40] => pdo_mysql [41] => pdo_sqlite )

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.