• Downloading from our site will require you to have a paid membership. Upgrade to a Premium Membership from 10$ a month today!

    Dont forget read our Rules! Also anyone caught Sharing this content will be banned. By using this site you are agreeing to our rules so read them. Saying I did not know is simply not an excuse! You have been warned.

Code php đóng dấu ảnh đơn giản

Admin

Well-Known Member
Staff member
Administrator
1. Tạo file index.php với nội dung
PHP:
<?php  if ((($_FILES["file"]["type"] == "image/gif") 
 || ($_FILES["file"]["type"] == "image/jpeg") 
 || ($_FILES["file"]["type"] == "image/pjpeg")) 
 && ($_FILES["file"]["size"] < 900000)) 
   { 
   if ($_FILES["file"]["error"] > 0) 
     { 
     echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; 
     } 
   else 
     { 
      
           $file_name = 'upload/'.substr(md5(time()),0,10).'.jpg'; 
           $file = imagecreatefromjpeg($_FILES["file"]["tmp_name"]); 
            
           $watermark = @imagecreatefrompng('./wm.png'); 
           $imagewidth = imagesx($file); 
           $imageheight = imagesy($file); 
           $watermarkwidth = imagesx($watermark); 
           $watermarkheight = imagesy($watermark); 
           $startwidth = (($imagewidth - $watermarkwidth)/1); 
           $startheight = (($imageheight - $watermarkheight)/1); 
           imagecopy($file, $watermark, $startwidth, $startheight, 0, 0, $watermarkwidth, $watermarkheight); 
           #imagecopymerge($file, $watermark, $startwidth, $startheight, 0, 0, $watermarkwidth, $watermarkheight, 80); 
            imagedestroy($watermark); 
            
           imagejpeg($file, $file_name, 90); 
           ImageDestroy($new); 
           ImageDestroy($file);      
      
     #echo "Upload: " . $_FILES["file"]["name"] . "<br />"; 
     #echo "Type: " . $_FILES["file"]["type"] . "<br />"; 
     #echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />"; 
     #echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />"; 
    echo '<img src="'.$file_name.'" alt=""/>'; 
     /*if (file_exists("upload/" . $_FILES["file"]["name"])) 
       { 
       echo $_FILES["file"]["name"] . " already exists. "; 
       } 
     else 
       { 
       move_uploaded_file($_FILES["file"]["tmp_name"], 
       "upload/" . $_FILES["file"]["name"]); 
       echo "Stored in: " . "upload/" . $_FILES["file"]["name"]; 
       }*/ 
     } 
   } 
 else 
   { 
   echo "Invalid file"; 
   } 
 ?> 
<html> 
 <body> 


 <form action="" method="post" 
 enctype="multipart/form-data"> 
 <label for="file">File:</label> 
 <input type="file" name="file" id="file" />  
 <br /> 
 <input type="submit" name="submit" value="Submit" /> 
 </form> 


 </body> 
 </html> 
  
<?php 
if ($handle = opendir('./upload/')) { 
    while (false !== ($entry = readdir($handle))) { 
        if ($entry != "." && $entry != "..") { 
            echo "<a href=\"upload/$entry\">$entry</a>, \n"; 
        } 
    } 
    closedir($handle); 
} 
?>


2. Tạo file ảnh watermark png nền trong suốt để làm con dấu với tên wm.png và up song song với index.php
3. tạo thư mục "upload" ngang hàng với index.phpchmod 0777
 
Của em đây
1. Tạo file index.php với nội dung
[TEXT][<?php if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 900000))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
}
else
{

$file_name = 'upload/'.substr(md5(time()),0,10).'.jpg';
$file = imagecreatefromjpeg($_FILES["file"]["tmp_name"]);

$watermark = @imagecreatefrompng('./wm.png');
$imagewidth = imagesx($file);
$imageheight = imagesy($file);
$watermarkwidth = imagesx($watermark);
$watermarkheight = imagesy($watermark);
$startwidth = (($imagewidth - $watermarkwidth)/1);
$startheight = (($imageheight - $watermarkheight)/1);
imagecopy($file, $watermark, $startwidth, $startheight, 0, 0, $watermarkwidth, $watermarkheight);
#imagecopymerge($file, $watermark, $startwidth, $startheight, 0, 0, $watermarkwidth, $watermarkheight, 80);
imagedestroy($watermark);

imagejpeg($file, $file_name, 90);
ImageDestroy($new);
ImageDestroy($file);

#echo "Upload: " . $_FILES["file"]["name"] . "<br />";
#echo "Type: " . $_FILES["file"]["type"] . "<br />";
#echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
#echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";
echo '<img src="'.$file_name.'" alt=""/>';
/*if (file_exists("upload/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"upload/" . $_FILES["file"]["name"]);
echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
}*/
}
}
else
{
echo "Invalid file";
}
?>
<html>
<body>


<form action="" method="post"
enctype="multipart/form-data">
<label for="file">File:</label>
<input type="file" name="file" id="file" />
<br />
<input type="submit" name="submit" value="Submit" />
</form>


</body>
</html>

<?php
if ($handle = opendir('./upload/')) {
while (false !== ($entry = readdir($handle))) {
if ($entry != "." && $entry != "..") {
echo "<a href=\"upload/$entry\">$entry</a>, \n";
}
}
closedir($handle);
}
?>][/TEXT]


2. Tạo file ảnh watermark png nền trong suốt để làm con dấu với tên wm.png và up song song với index.php
3. tạo thư mục "upload" ngang hàng với index.phpchmod 0777
 

Facebook Comments

New posts New threads New resources

Back
Top