Jump to content

Recommended Posts

can some one help me put these 2 codes together i've been trying for ages..

i would realy appreciate it

 

function generate_rand($l){
$c= "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
srand((double)microtime()*1000000);
for($i=0; $i<$l; $i++)
{
$rand.= $c[rand()%strlen($c)];
}
return $rand;
}

if($_POST[submit])
{
include("inc/config.php");
$uploaddir = "uploads/avatars/";
$maxfilesize = 153600; 
$filename = $_FILES['file']['name'];
$filesize = $_FILES['file']['size'];
$filetmpname = $_FILES['file']['tmp_name'];
$valid = array (".jpg",".gif",".png");
if ($filename) {
$error = "";
if ($filesize == 0) {
$error .= "The submitted file was invalid.<br />";
}
$type = strtolower(strstr($filename, '.'));
if (!in_array($type, $valid)) {
$error .= "The submitted file was of invalid type.<br />";
}
if ($filesize>$maxfilesize) {
$error .= "The submitted file was larger than a Megabyte.<br />";
}
$randnum = generate_rand(10);
$randnum .= $type;
$file_exists = true;
while ($file_exists) {
if (file_exists("$uploaddir$randnum")) {
$randnum = generate_rand(10);
$randnum .= $type;
}else{
$file_exists = false;
}
}
if ($error == "") {
if (move_uploaded_file($filetmpname, "$uploaddir$randnum")) {
chmod("$uploaddir$randnum", 0644);
echo "Your file was successfully uploaded!<br />";

mysql_query("UPDATE `members` SET `avatar`= '$uploaddir$randnum' WHERE `id` = '$user[id]'");
echo "<a href=\"?action=memberlist&id=$logged[id]\">Click here to go to your profile</a>"; } else {
echo "Your file could not be uploaded.";
}
}else{
echo $error;
}
}else{
echo "No file was uploaded";
}
}
?>

 

if ($width > $height)
   {
    $ratio = (250/$width);
    $new_width = round($width*$ratio);
    $new_height = round($height*$ratio);
   }
  else
   {
    $ratio = (250/$height);
    $new_width = round($width*$ratio);
    $new_height = round($height*$ratio);
   }
  $image_p = imagecreatetruecolor($new_width,$new_height);
  $image = imagecreatefromjpeg($image_name);
  imagecopyresampled($image_p,$image,0,0,0,0,$new_width,$new_height,$width,$height);
  imagejpeg($image_p,$new_image_name,100);
  echo("Image uploaded!");
}

Link to comment
https://forums.phpfreaks.com/topic/52422-image-uploading-script-help/
Share on other sites

Guest
This topic is now 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.