Помощ За Ъплоуд

  • Автор Автор kini
  • Начална дата Начална дата

kini

Registered
Здравейте някой може ли да ми помогне
давам ъплоуд код и код за воден знак нужно е да се вгради водния знак във ъплоуда пробвах сам да барна тук там но не става :(

Ъплоуд 1:

Код:
<?
if($_POST['upload'])
{
$ext = array('jpg','jpeg');
$extnafaila = end(explode('.',$_FILES['uploadfile']['name']));
$extnafaila = strtolower($extnafaila);
if(in_array($extnafaila,$ext)){
if($urow['osnovna']) { $osnovna = $urow['osnovna']; $osnovna_big = $urow['osnovna_big']; @unlink($osnovna); @unlink($osnovna_big); $uid = $urow['id']; $sql = mysql_query("UPDATE users SET osnovna='', osnovna_big='', active='no' WHERE id='$uid'"); }
// This is the temporary file created by PHP
$uploadedfile = $_FILES['uploadfile']['tmp_name'];

// Create an Image from it so we can do the resize
$src = imagecreatefromjpeg($uploadedfile);

// Capture the original size of the uploaded image
list($width,$height)=getimagesize($uploadedfile);

// For our purposes, I have resized the image to be
// 600 pixels wide, and maintain the original aspect
// ratio. This prevents the image from being "stretched"
// or "squashed". If you prefer some max width other than
// 600, simply change the $newwidth variable
$newheight=127;
$newwidth=($width/$height)*$newheight;
$tmp=imagecreatetruecolor($newwidth,$newheight);

// this line actually does the image resizing, copying from the original
// image into the $tmp image
imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);

// now write the resized image to disk. I have assumed that you want the
// resized, uploaded image file to reside in the ./images subdirectory.
$file5 = $_FILES['uploadfile']['name'];
$randfile = rand(00000,99999);
$file2 = $file5.randfile;
$mdfile = md5($file2);
//$filename = "thumbs/". $_FILES['uploadfile']['name'];
$filename = "photo/". $_SESSION[username] . $mdfile ."_osnovna.jpg";
imagejpeg($tmp,$filename,100);

imagedestroy($src);
imagedestroy($tmp); // NOTE: PHP will clean up the temp file it created when the request
$uid = $urow['id'];
$sql = mysql_query("UPDATE users SET osnovna='$filename', active='no' WHERE id='$uid'");

$uploadedfile = $_FILES['uploadfile']['tmp_name'];

// Create an Image from it so we can do the resize
$src = imagecreatefromjpeg($uploadedfile);

// Capture the original size of the uploaded image
list($width,$height)=getimagesize($uploadedfile);

// For our purposes, I have resized the image to be
// 600 pixels wide, and maintain the original aspect
// ratio. This prevents the image from being "stretched"
// or "squashed". If you prefer some max width other than
// 600, simply change the $newwidth variable
$newheight=240;
$newwidth=($width/$height)*$newheight;
$tmp=imagecreatetruecolor($newwidth,$newheight);

// this line actually does the image resizing, copying from the original
// image into the $tmp image
imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);

// now write the resized image to disk. I have assumed that you want the
// resized, uploaded image file to reside in the ./images subdirectory.
$file5 = $_FILES['uploadfile']['name'];
$randfile = rand(00000,99999);
$file2 = $file5.randfile;
$mdfile = md5($file2);
//$filename = "thumbs/". $_FILES['uploadfile']['name'];
$filename = "photo/". $_SESSION[username] . $mdfile ."_osnovna_normal.jpg";
imagejpeg($tmp,$filename,100);

imagedestroy($src);
imagedestroy($tmp); // NOTE: PHP will clean up the temp file it created when the request
$uid = $urow['id'];
$sql = mysql_query("UPDATE users SET osnovna_normal='$filename', active='no' WHERE id='$uid'");

$uploadedfile = $_FILES['uploadfile']['tmp_name'];

// Create an Image from it so we can do the resize
$src = imagecreatefromjpeg($uploadedfile);

// Capture the original size of the uploaded image
list($width,$height)=getimagesize($uploadedfile);

// For our purposes, I have resized the image to be
// 600 pixels wide, and maintain the original aspect
// ratio. This prevents the image from being "stretched"
// or "squashed". If you prefer some max width other than
// 600, simply change the $newwidth variable
$newheight=500;
$newwidth=($width/$height)*$newheight;
$tmp=imagecreatetruecolor($newwidth,$newheight);

// this line actually does the image resizing, copying from the original
// image into the $tmp image
imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);

// now write the resized image to disk. I have assumed that you want the
// resized, uploaded image file to reside in the ./images subdirectory.
$file5 = $_FILES['uploadfile']['name'];
$randfile = rand(00000,99999);
$file2 = $file5.randfile;
$mdfile = md5($file2);
//$filename = "thumbs/". $_FILES['uploadfile']['name'];
$filename = "photo/". $_SESSION[username] . $mdfile ."_osnovna_big.jpg";
imagejpeg($tmp,$filename,100);

imagedestroy($src);
imagedestroy($tmp); // NOTE: PHP will clean up the temp file it created when the request
$uid = $urow['id'];
$sql = mysql_query("UPDATE users SET osnovna_big='$filename', active='no' WHERE id='$uid'");
$sql = mysql_query("SELECT * FROM users WHERE id='$uid'");
$urow = mysql_fetch_array($sql);
}
else {
?>

Код Воден Знак:
Код:
<?php 

$target = "tmp/"; //Директорията за качване 
$target = $target . basename( $_FILES['uploaded']['name']) ; 
$ok=1; 


//Това е ограничението ни за размер 
if ($_FILES['uploaded']['size'] > 3500000) //3.33786011 мегабайта 
{ 
echo "Вашия файл е твърде голям.<br>"; 
$ok=0; 
exit; 
} 
//Това е ограничението за вид на файла // 
$ext = array('jpg','jpeg'); 
$extnafaila = end(explode('.',$_FILES['uploaded']['name'])); 
$extnafaila = strtolower($extnafaila); 
if(!in_array($extnafaila,$ext)){ 
echo "Можете да качвате само файлове jpg и jpeg"; 
$ok=0; 
exit; 
} 

//Проверка дали файл със същото име вече не съществува в директорията 

$fn = basename( $_FILES['uploaded']['name']); 

$name_arr = explode('.',$fn); // 

$failime = "./img/$name_arr[0].png"; 


if (file_exists($failime)) { 
echo "Файлът $filename съществува<br>"; 
$ok=0; 
exit; 
} else { 
echo "Файлът $filename не съществува на сървъра.... Продължаваме<br>"; 
} 
//Тук проверяваме дали по-горе извършените проверки са дали грешки 
if ($ok==0) 
{ 
Echo "Не стана"; 
} 

//Ако всичко е наред качваме файла на хоста 
else 
{ 
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) 
{ 
echo "Файла ".basename( $_FILES['uploaded']['name']). " беше качен...<br /> Почваме водния знак... <br />"; 

} 
else 
{ 
echo "Не стана 2"; //тук показва грешка ако файла не е качен правилно 
exit; 
} 
} 

//$fn = basename( $_FILES['uploaded']['name']); след редакция - зададени са по-нагоре 

//$name_arr = explode('.',$fn); //махаме разширението jpg на оригиналния файл, изх. картинка е png - след редакция е зададено при проверката за съществуване 

$kade = "./img/$name_arr[0].png"; 

$Watermark = imagecreatefrompng("watermark.png"); //тук си задаваде файла които е водния знак, png 

$putq = "tmp/".basename( $_FILES['uploaded']['name']). ""; 

$Image = imagecreatefromjpeg("$putq"); 


imagecolortransparent($Watermark,imagecolorat($Watermark,0,0)); 


$PosX = imagesx($Image)-imagesx($Watermark)-5; 
$PosY = imagesy($Image)-imagesy($Watermark)-5; 
imagecopymerge($Image,$Watermark,$PosX,$PosY,0,0,imagesx($Watermark),imagesy($Watermark),25); 


imagepng($Image, $kade); 

if (unlink("tmp/$fn")) { 
echo "Временния файл е изтрит... Даваме линк към готовата картинка <br />"; 
} else { 
echo "Не се изтри временния файл <br />"; 
} 

echo "<a href='$kade'>Виж картинката</a>"; 

?>
реших да ползвам този код http://web-tourist.net/login/login/view.php?st=2545 защото като не открих друг
благодаря ви предварително
 

Back
Горе