منتدى فيجوال بيسك لكل العرب | منتدى المبرمجين العرب
طلب اضافة ختم الصور لهذا الكود - نسخة قابلة للطباعة

+- منتدى فيجوال بيسك لكل العرب | منتدى المبرمجين العرب (https://vb4arb.com/vb)
+-- قسم : قسم برمجة وتطوير المواقع (https://vb4arb.com/vb/forumdisplay.php?fid=51)
+--- قسم : قسم PHP (https://vb4arb.com/vb/forumdisplay.php?fid=58)
+---- قسم : قسم اسئلة PHP (https://vb4arb.com/vb/forumdisplay.php?fid=59)
+---- الموضوع : طلب اضافة ختم الصور لهذا الكود (/showthread.php?tid=56206)

الصفحات: 1 2 3 4 5


RE: طلب اضافة ختم الصور لهذا الكود - nnnjk - 04-04-26

موقعي تعرض للاختراق ورفع صفحة index وتداركت الوضع وعملت على اصلاحها وتبليغ صاحب الاستضافه بالاختراق

فعلا المشكلة ليست بعدد حروف نوع الملف كانت اربعه ام كانت ثلاثه
هذه الصوره نقلها لموقعي وختمها
https://media.assettype.com/ajel%2F2026-01-06%2Fgkhrxbgp%2F5566777.avif


RE: طلب اضافة ختم الصور لهذا الكود - Amir_Alzubidy - 04-04-26

(04-04-26, 03:35 PM)nnnjk كتب : فعلا المشكلة ليست بعدد حروف نوع الملف كانت اربعه ام كانت ثلاثه
هذه الصوره نقلها لموقعي وختمها
https://media.assettype.com/ajel%2F2026-01-06%2Fgkhrxbgp%2F5566777.avif

جيد اذاً نستخلص بعض الامور
مشكلتك غالباً واحدة على الاقل من هذه المشاكل :
1-السيرفر يمنع السحب (Hotlink protection)
2-حماية السيرفر (Hotlink / Referer)
بعض المواقع خصوصاً الإخبارية
تمنع تحميل الصورة من خارج الموقع أو تحتاج Referer
وليست بسبب طول الامتداد (3 أو 4 أحرف)

بالتوفيق

عذراً , لكن لم افهم ما مشكلة الاختراق !


RE: طلب اضافة ختم الصور لهذا الكود - nnnjk - 04-04-26

قام احد الهكر بااختراق بعض صفحات موقعي ولم اعلم بها الا امس وعملت على اصلاح الموقع ومراسلة المستضيف يعمل لموقعي حماية


RE: طلب اضافة ختم الصور لهذا الكود - Amir_Alzubidy - 04-04-26

لا باس , لعله خير
طيب شوف استضافة آمنة و مستقرة على الاقل تحمي خصوصيتك و خصوصيات المستخدمين
تحياتي لك .


RE: طلب اضافة ختم الصور لهذا الكود - nnnjk - 04-04-26

لاكن الملف webp له حالة خاصه لاينقل الملف من موقع عادي وليس ذو حماية اكد ان المشكلة بنوعية الملف ينقل جميع الصور ماعدا هذا الامتداد
والسكربت الذي وضعت رابطه لك يرفع جميع انواع الملفات ماعدا موقع ويكيبيديا
وتعديلك لكود الكلش يجعل يسحب الملفات من موقع الرياض وموقع ويكبيديا وسبق ويختم صورهم
ماعدا موقع خبرني والمرصد فقام بنقل الصور وتغيير نوعها و(لم يختم الصوره باامتداد webp)


RE: طلب اضافة ختم الصور لهذا الكود - Amir_Alzubidy - 04-04-26

(04-04-26, 04:15 PM)nnnjk كتب : لاكن الملف webp له حالة خاصه لاينقل الملف من موقع عادي وليس ذو حماية اكد ان المشكلة بنوعية الملف ينقل جميع الصور ماعدا هذا الامتداد
والسكربت الذي وضعت رابطه لك يرفع جميع انواع الملفات ماعدا موقع ويكيبيديا
وتعديلك لكود الكلش يجعل يسحب الملفات من موقع الرياض وموقع ويكبيديا وسبق ويختم صورهم
ماعدا موقع خبرني والمرصد فقام بنقل الصور وتغيير نوعها و(لم يختم الصوره باامتداد webp)

بعض الصور WebP تكون مضغوطة بطريقة حديثة (lossless / alpha)
و طبيعي imagecreatefromstring() يفشل معها 

بعض المواقع (مثل خبرني والمرصد) ترجع WebP لكن تحتاج headers خاصة أو ترجع بيانات ناقصة أول مرة
بعض السيرفرات ترجع الصورة WebP لكن Header ناقص  لذلك لا يتم الاستفادة من getimagesize() 

بعد هذا التعديل اذا فيه صورة ما تنسحب هنا نكون دخلنا دوامة الـ Cloudflare / Cookies

PHP كود :
<?php
function GetCacheID() {
    global $db;
    $SQL "INSERT INTO " TABLE_PREFIX "y2ksw_imgcache2 (ID) VALUES (0)";
    $db->query_write($SQL);
    return $db->insert_id();
}
function 
DownloadImage($url) {
    if (empty($url)) return false;
    $context stream_context_create([
        'http' => [
            'header' => "User-Agent: Mozilla/5.0\r\n"
        ],
        'ssl' => [
            'verify_peer' => false,
            'verify_peer_name' => false,
        ],
    ]);
    $data = @file_get_contents($urlfalse$context);
    if ($data === false || strlen($data) < 100) {
        $ch curl_init($url);
        curl_setopt_array($ch, [
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_FOLLOWLOCATION => true,
            CURLOPT_SSL_VERIFYPEER => false,
            CURLOPT_SSL_VERIFYHOST => false,
            CURLOPT_TIMEOUT => 20,
            CURLOPT_USERAGENT => 'Mozilla/5.0',
            CURLOPT_HTTPHEADER => [
                'Accept: image/webp,image/apng,image/*,*/*;q=0.8',
                'Referer: ' $url
            
]
        ]);
        $data curl_exec($ch);
        curl_close($ch);
    }
    return $data;
}
function 
CacheImages($message_body$old_message$forum_home) {
    $files = [];
    $n 0;
    $pos_end = -1;
    while (($pos_start strpos(strtolower($message_body), '[img]'$pos_end 1)) !== false) {
        $pos_end strpos(strtolower($message_body), '[/img]'$pos_start 1);
        if ($pos_end === false) break;
        $pos_start += 5;
        $pos_end--;
        $url trim(substr($message_body$pos_start$pos_end $pos_start 1));
        $files[$n]['url'] = $url;
        $n++;
    }
    if (!$n) return $old_message;
    foreach ($files as $i => $file) {
        if (empty($file['url'])) continue;
        if (!empty($forum_home) && strpos($file['url'], $forum_home 'imgcache/2/') !== false) {
            $files[$i]['url'] = '';
            continue;
        }
        $matar strtolower($file['url']);
        if (preg_match("/alshafeen.site|alsh3er.com/i"$matar)) {
            $files[$i]['url'] = '';
            continue;
        }
    }
    for ($i 0$i $n$i++) {
        if (empty($files[$i]['url'])) continue;
        for ($j $i 1$j $n$j++) {
            if ($files[$j]['url'] == $files[$i]['url']) {
                $files[$j]['url'] = '';
            }
        }
    }
    foreach ($files as $file) {
        if (empty($file['url'])) continue;
        $content DownloadImage($file['url']);
        if (!$content) continue;
        $tmp tempnam(sys_get_temp_dir(), "img_");
        file_put_contents($tmp$content);
        $info = @getimagesize($tmp);
        $is_webp false;
        if ($info && isset($info['mime']) && $info['mime'] == 'image/webp') {
            $is_webp true;
        }
        if (!$info && strpos($file['url'], '.webp') !== false) {
            $is_webp true;
        }
        $id GetCacheID();
        $new_file 'imgcache/2/' $id 'alsh3er.jpg';
        if ($is_webp) {
            $img = @imagecreatefromstring(file_get_contents($tmp));
            if ($img) {
                imagejpeg($img$new_file90);
                imagedestroy($img);
            } else {
                copy($tmp$new_file);
            }
        } else {
            copy($tmp$new_file);
        }
        unlink($tmp);
        AddWatermark($new_file"alsh3er.site");
        $old_message str_replace($file['url'], $forum_home $new_file$old_message);
    }
    return $old_message;
}
function 
AddWatermark($imagePath$text) {
    $data = @file_get_contents($imagePath);
    if (!$data) return;
    $img = @imagecreatefromstring($data);
    if (!$img) return;
    $color imagecolorallocatealpha($img25525525550);
    imagestring(
        $img,
        3,
        imagesx($img) - 120,
        imagesy($img) - 15,
        $text,
        $color
    
);
    imagejpeg($img$imagePath90);
    imagedestroy($img);
}
?>



RE: طلب اضافة ختم الصور لهذا الكود - nnnjk - 04-04-26

اسف على التأخير
جربت الكود الاخير نقل الصوره من صحيفة المرصد ولم يختمها


RE: طلب اضافة ختم الصور لهذا الكود - Amir_Alzubidy - 04-04-26

(04-04-26, 05:30 PM)nnnjk كتب : اسف على التأخير
جربت الكود الاخير نقل الصوره من صحيفة المرصد ولم يختمها

استبدل دالة الختم فقط 

PHP كود :
function AddWatermark($imagePath$text) {

    $data = @file_get_contents($imagePath);
    if (!$data) return;

    $img = @imagecreatefromstring($data);

   
    
if (!$img) {
        $tmp = @imagecreate(800600);
        if (!$tmp) return;

        $bg imagecolorallocate($tmp000);
        imagefill($tmp00$bg);

        imagejpeg($tmp$imagePath90);
        imagedestroy($tmp);

        $img = @imagecreatefromjpeg($imagePath);
        if (!$img) return;
    }

    $width  imagesx($img);
    $height imagesy($img);

    $color imagecolorallocatealpha($img25525525550);

    $x $width 120;
    $y $height 15;

    imagestring($img3$x$y$text$color);

    imagejpeg($img$imagePath90);

    imagedestroy($img);




RE: طلب اضافة ختم الصور لهذا الكود - nnnjk - 04-04-26

اضافة الى ماسبق يبدوا ان دالة سحب الملف ودالة ختم الصور لهما الدور الاساسي في النقل
هذا كود سكربت بسيط لسحب الملفات من رابط يسحب جميع الصور ويختمها سوا من صحيفة المرصد او صحيفة الرياض او خبرني لاكن لاينقل الصور من موقع ويكيبيديا
<?php
function watermark($name, $ext, $logo){

if (preg_match("/jpg|jpeg/",$ext)){$src_img=imagecreatefromjpeg($name);}

if (preg_match("/webp/",$ext)){$src_img=imagecreatefromwebp($name);}
if (preg_match("/png/",$ext)){$src_img=imagecreatefrompng($name);}
if (preg_match("/gif/",$ext)){$src_img=imagecreatefromgif($name);}

$src_logo = imagecreatefrompng($logo);

    $bwidth  = imageSX($src_img);
    $bheight = imageSY($src_img);
    $lwidth  = imageSX($src_logo);
    $lheight = imageSY($src_logo);

//fix bug for 1beta3
if ( $bwidth > 160 &&  $bheight > 130 ) {

    $src_x = $bwidth - ($lwidth + 5);
    $src_y = $bheight - ($lheight + 5);
    ImageAlphaBlending($src_img, true);
    ImageCopy($src_img,$src_logo,$src_x,$src_y,0,0,$lwidth,$lheight);

if (preg_match("/jpg|jpeg/",$ext)){imagejpeg($src_img, $name);}
if (preg_match("/png/",$ext)){imagepng($src_img, $name);}
if (preg_match("/webp/",$ext)){imagewebp($src_img, $name);}
if (preg_match("/gif/",$ext)){imagegif($src_img, $name);}

}# < 150
else
{
return false;
}

}
$context = stream_context_create([
    'ssl' => [
        'verify_peer' => false,
        'verify_peer_name' => false,
    ],
]);
//blog.theonlytutorials.com
//author: agurchand

$memory_limit='128M';

$max_execution_time='300';
if($_POST){
//get the url
$url = $_POST['url'];

//add time to the current filename
$name = basename($url);
list($txt, $ext) = explode(".", $name);
$name = time();
$name = $name.".".$ext;


$ext=".jpg".$ext;
// $ext = end($sepext);     
/*$t=array('jpg' , 'png' , 'gif','ip' , 'rar');
    if(!in_array($ext,$t))
{ echo gggg;}else  {
*/
//here is the actual code to get the file from the url and save it to the uploads folder
//get the file from the url using file_get_contents and put it into the folder using file_put_contents
$upload = file_put_contents("uploads/$name",file_get_contents($url,false,$context));
$fileplace="uploads";

@watermark($fileplace."/".$name,$ext,'logo/logo.png');
//include('Thumbnail.class.php');
// $thumb=new Thumbnail("$name");
// $thumb->quality='100'; 

      // $thumb->process();   
      // generate image
// $thumb->save("$name");
  $filesk= "$name";
//$name = str_replace("?format=jpg","gg",$filesk);
echo $TXTREM ;
//check success
if($upload)
echo "Success:$name <a href='uploads/".$name."' target='_blank'>Check Uploaded</a>"; else "please check your folder permission";
}
//}
?>

<html>
<head><title>Theonlytutorials - Simple File Upload from URL Script!</title></head>
<body>
<h3>Theonlytutorials.com - Very Simple File Upload from URL Script!</h3>
<form action="" method="post">
Your URL: <input type="text" name="url" />
<input type="submit" value="upload Images" name="upload"/>
</form>
</body>
</html>

الله يعطيك العافيه على المجهود
ختم الصوره لاكن ظهرت سوداء ليس فيها محتوى


RE: طلب اضافة ختم الصور لهذا الكود - Amir_Alzubidy - 04-04-26

تعديل دالة AddWatermark

PHP كود :
function AddWatermark($imagePath$text) {

    $data = @file_get_contents($imagePath);
    if (!$data) return;

    $img = @imagecreatefromstring($data);

    if (!$img) {
        return; // لا تخرب الصورة إذا فشل
    }

    $width  imagesx($img);
    $height imagesy($img);

    $color imagecolorallocatealpha($img25525525550);

    $x $width 120;
    $y $height 15;

    imagestring($img3$x$y$text$color);

    imagejpeg($img$imagePath90);

    imagedestroy($img);


احتمال اخر اذا ما ضبط معك الاول 
PHP كود :
function AddWatermark($imagePath$text) {

    $ext strtolower(pathinfo($imagePathPATHINFO_EXTENSION));

    if ($ext == 'jpg' || $ext == 'jpeg') {
        $img = @imagecreatefromjpeg($imagePath);
    } elseif ($ext == 'png') {
        $img = @imagecreatefrompng($imagePath);
    } elseif ($ext == 'gif') {
        $img = @imagecreatefromgif($imagePath);
    } elseif ($ext == 'webp') {
        $img = @imagecreatefromwebp($imagePath);
    } else {
        return;
    }

    if (!$img) return;

    $width  imagesx($img);
    $height imagesy($img);

    $color imagecolorallocatealpha($img25525525550);

    $x $width 120;
    $y $height 15;

    imagestring($img3$x$y$text$color);

    if ($ext == 'jpg' || $ext == 'jpeg') {
        imagejpeg($img$imagePath90);
    } elseif ($ext == 'png') {
        imagepng($img$imagePath);
    } elseif ($ext == 'gif') {
        imagegif($img$imagePath);
    } elseif ($ext == 'webp') {
        imagewebp($img$imagePath);
    }

    imagedestroy($img);