03-04-26, 11:07 PM
السلام عليكم ركبت سكربت سحب الملف من رابط ولم يعمل وتأتي رسالة تم تعطيل shell_exec Warning: shell_exec() has been disabled for security reasons in كيف افعلها من الملف او من خلال ملف htaccess
(03-04-26, 11:07 PM)nnnjk كتب : [ -> ]السلام عليكم ركبت سكربت سحب الملف من رابط ولم يعمل وتأتي رسالة تم تعطيل shell_exec Warning: shell_exec() has been disabled for security reasons in كيف افعلها من الملف او من خلال ملف htaccess
$url = "https://example.com/file.jpg";
$ch = curl_init($url);
$fp = fopen("file.jpg", "w");
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_exec($ch);
curl_close($ch);
fclose($fp);
<title>الاتصال</title>
<?php require('login.php');?>
<?php if($_SESSION['username']): ?>
<html>
<head>
<style>
input[type=text], select {
width: 100%;
padding: 12px 20px;
margin: 8px 0;
display: inline-block;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
text-align: center;
}
input[type=submit] {
width: 100%;
background-color: #4CAF50;
color: white;
padding: 14px 20px;
margin: 8px 0;
border: none;
border-radius: 4px;
cursor: pointer;
}
input[type=submit]:hover {
background-color: #45a049;
}
div {
border-radius: 5px;
padding: 20px;
}
body {
background-image: url("http://akveo.com/blur-admin/assets/img/blur-bg-blurred.jpg");
}
</style>
</head>
<body>
<div>
<center>
<a href="logout.php"><img src="http://findicons.com/files/icons/2146/realistik_reloaded/128/exit.png" height="42" width="42"></a>
<center>
<hr><br>
<h2 style="padding: 1px;background: rgba(255, 152, 0, 0.84);width: 15%;">تحميل ملف جديد</h2>
<form action="index.php?do=download" method="post">
<input dir="rtl" required type="text" name="link" placeholder="الرابط المباشر للتحميل"><br>
<input dir="rtl" required type="text" name="dir" placeholder="المسار االذي تريد وضع الملف فيه"><br>
<input style="background-color: #00BCD4;" type="submit" value="! ابدا الان">
</form>
<?php
$link = $_POST['link'];
$dir = $_POST['dir'];
$do = $_GET['do'];
if ($do =="download")
{
chdir($dir);
$download = shell_exec("wget $link");
echo $download;
echo "<input type='submit' style='width: 50%;' value='تم التحميل بنجاح الى المجلد المختار'>";
echo "<meta http-equiv='refresh' content='2; url=index.php' />";
}
else{}
?>
<?php endif;?><?php
session_start();
require('login.php');
if (!isset($_SESSION['username'])) {
die("يجب تسجيل الدخول");
}
?>
<!DOCTYPE html>
<html>
<head>
<title>تحميل ملف</title>
<style>
input[type=text], select {
width: 100%;
padding: 12px;
margin: 8px 0;
border: 1px solid #ccc;
border-radius: 4px;
text-align: center;
}
input[type=submit] {
width: 100%;
background-color: #4CAF50;
color: white;
padding: 14px;
border: none;
border-radius: 4px;
}
body {
background-image: url("http://akveo.com/blur-admin/assets/img/blur-bg-blurred.jpg");
}
</style>
</head>
<body>
<div style="width:50%;margin:auto;">
<center>
<a href="logout.php">تسجيل خروج</a>
<hr>
<h2>تحميل ملف جديد</h2>
<form method="post">
<input required type="text" name="link" placeholder="الرابط المباشر"><br>
<input required type="text" name="dir" placeholder="المجلد (مثال: uploads/)"><br>
<input type="submit" name="download" value="ابدأ التحميل">
</form>
<hr>
<?php
if (isset($_POST['download'])) {
$link = trim($_POST['link']);
$dir = trim($_POST['dir']);
// ✅ التحقق من الرابط
if (!filter_var($link, FILTER_VALIDATE_URL)) {
die("❌ رابط غير صالح");
}
// ✅ حماية المسار (منع الخروج خارج الموقع)
if (strpos($dir, "..") !== false) {
die("❌ مسار غير مسموح");
}
// ✅ إنشاء المجلد إذا غير موجود
if (!is_dir($dir)) {
mkdir($dir, 0755, true);
}
// ✅ بدء cURL
$ch = curl_init($link);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HEADER => true,
CURLOPT_NOBODY => false,
CURLOPT_TIMEOUT => 300,
]);
$response = curl_exec($ch);
if (curl_errno($ch)) {
die("❌ خطأ: " . curl_error($ch));
}
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$headers = substr($response, 0, $header_size);
$body = substr($response, $header_size);
// ✅ محاولة استخراج اسم الملف من الهيدر
$filename = "";
if (preg_match('/Content-Disposition:.*filename=["\']?([^"\']+)/i', $headers, $matches)) {
$filename = $matches[1];
}
// إذا لم يتم العثور عليه
if (!$filename) {
$filename = basename(parse_url($link, PHP_URL_PATH));
}
// إذا فاضي
if (!$filename || strlen($filename) < 3) {
$filename = "file_" . time();
}
$filepath = rtrim($dir, "/") . "/" . $filename;
// ✅ حفظ الملف
if (file_put_contents($filepath, $body)) {
echo "✅ تم التحميل بنجاح<br>";
echo "? المسار: " . $filepath;
} else {
echo "❌ فشل حفظ الملف";
}
curl_close($ch);
}
?>
</center>
</div>
</body>
</html>
(04-04-26, 04:12 AM)nnnjk كتب : [ -> ]يعطيك العافيه
تم رفع الملف ويكتب رابط الملف مع المجلد
لاكن عند الدخول اليه صفحة 404 لم يوجد الملف
<?php
session_start();
require('login.php');
if (!isset($_SESSION['username'])) {
die("يجب تسجيل الدخول");
}
?>
<!DOCTYPE html>
<html>
<head>
<title>تحميل ملف</title>
<style>
input[type=text] {
width: 100%;
padding: 12px;
margin: 8px 0;
border: 1px solid #ccc;
border-radius: 4px;
text-align: center;
}
input[type=submit] {
width: 100%;
background-color: #4CAF50;
color: white;
padding: 14px;
border: none;
border-radius: 4px;
}
body {
background-image: url("http://akveo.com/blur-admin/assets/img/blur-bg-blurred.jpg");
}
</style>
</head>
<body>
<div style="width:50%;margin:auto;">
<center>
<a href="logout.php">تسجيل خروج</a>
<hr>
<h2>تحميل ملف جديد</h2>
<form method="post">
<input required type="text" name="link" placeholder="الرابط المباشر"><br>
<input required type="text" name="dir" placeholder="اسم المجلد (مثال: uploads)"><br>
<input type="submit" name="download" value="ابدأ التحميل">
</form>
<hr>
<?php
if (isset($_POST['download'])) {
$link = trim($_POST['link']);
$dir = trim($_POST['dir']);
// ✅ التحقق من الرابط
if (!filter_var($link, FILTER_VALIDATE_URL)) {
die("❌ رابط غير صالح");
}
// ✅ منع الاختراق
if (strpos($dir, "..") !== false) {
die("❌ مسار غير مسموح");
}
// ✅ المسار الحقيقي داخل public_html
$basePath = __DIR__; // مكان السكربت (داخل public_html)
$fullDir = $basePath . "/" . $dir;
// ✅ إنشاء المجلد إذا غير موجود
if (!is_dir($fullDir)) {
mkdir($fullDir, 0755, true);
}
// ✅ بدء التحميل
$ch = curl_init($link);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HEADER => true,
CURLOPT_TIMEOUT => 300,
]);
$response = curl_exec($ch);
if (curl_errno($ch)) {
die("❌ خطأ: " . curl_error($ch));
}
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$headers = substr($response, 0, $header_size);
$body = substr($response, $header_size);
// ✅ استخراج اسم الملف
$filename = "";
if (preg_match('/Content-Disposition:.*filename=["\']?([^"\']+)/i', $headers, $matches)) {
$filename = $matches[1];
}
if (!$filename) {
$filename = basename(parse_url($link, PHP_URL_PATH));
}
if (!$filename || strlen($filename) < 3) {
$filename = "file_" . time();
}
// تنظيف الاسم
$filename = preg_replace('/[^a-zA-Z0-9\.\-_]/', '_', $filename);
$filepath = $fullDir . "/" . $filename;
// ✅ حفظ الملف
if (file_put_contents($filepath, $body)) {
// رابط الوصول
$fileUrl = $dir . "/" . $filename;
echo "✅ تم التحميل بنجاح<br><br>";
echo "? تم الحفظ في: " . $filepath . "<br><br>";
echo "<a href='$fileUrl' target='_blank'>? فتح الملف</a>";
} else {
echo "❌ فشل حفظ الملف";
}
curl_close($ch);
}
?>
</center>
</div>
</body>
</html>
<?php
session_start();
require('login.php');
if (!isset($_SESSION['username'])) {
die("يجب تسجيل الدخول");
}
?>
<!DOCTYPE html>
<html>
<head>
<title>تحميل ملف</title>
<style>
input[type=text] {
width: 100%;
padding: 12px;
margin: 8px 0;
border: 1px solid #ccc;
border-radius: 4px;
text-align: center;
}
input[type=submit] {
width: 100%;
background-color: #4CAF50;
color: white;
padding: 14px;
border: none;
border-radius: 4px;
}
body {
background-image: url("http://akveo.com/blur-admin/assets/img/blur-bg-blurred.jpg");
}
</style>
</head>
<body>
<div style="width:50%;margin:auto;">
<center>
<a href="logout.php">تسجيل خروج</a>
<hr>
<h2>تحميل ملفين جديدين</h2>
<form method="post">
<b>الملف الأول:</b><br>
<input required type="text" name="link1" placeholder="الرابط المباشر الأول"><br>
<b>الملف الثاني:</b><br>
<input required type="text" name="link2" placeholder="الرابط المباشر الثاني"><br>
<input required type="text" name="dir" placeholder="اسم المجلد (مثال: uploads)"><br>
<input type="submit" name="download" value="ابدأ التحميل">
</form>
<hr>
<?php
function downloadFile($link, $fullDir) {
if (!filter_var($link, FILTER_VALIDATE_URL)) {
return ["success" => false, "msg" => "❌ رابط غير صالح: $link"];
}
$ch = curl_init($link);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HEADER => true,
CURLOPT_TIMEOUT => 300,
]);
$response = curl_exec($ch);
if (curl_errno($ch)) {
$err = curl_error($ch);
curl_close($ch);
return ["success" => false, "msg" => "❌ خطأ cURL: $err"];
}
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$headers = substr($response, 0, $header_size);
$body = substr($response, $header_size);
curl_close($ch);
// استخراج اسم الملف
$filename = "";
if (preg_match('/Content-Disposition:.*filename=["\']?([^"\';\r\n]+)/i', $headers, $matches)) {
$filename = trim($matches[1]);
}
if (!$filename) {
$filename = basename(parse_url($link, PHP_URL_PATH));
}
if (!$filename || strlen($filename) < 3) {
$filename = "file_" . time() . rand(100, 999);
}
$filename = preg_replace('/[^a-zA-Z0-9\.\-_]/', '_', $filename);
$filepath = $fullDir . "/" . $filename;
if (file_put_contents($filepath, $body)) {
return ["success" => true, "filepath" => $filepath, "filename" => $filename];
} else {
return ["success" => false, "msg" => "❌ فشل حفظ الملف: $filename"];
}
}
if (isset($_POST['download'])) {
$link1 = trim($_POST['link1']);
$link2 = trim($_POST['link2']);
$dir = trim($_POST['dir']);
if (strpos($dir, "..") !== false) {
die("❌ مسار غير مسموح");
}
$basePath = __DIR__;
$fullDir = $basePath . "/" . $dir;
if (!is_dir($fullDir)) {
mkdir($fullDir, 0755, true);
}
$links = [$link1, $link2];
foreach ($links as $i => $link) {
$num = $i + 1;
echo "<b>الملف $num:</b><br>";
$result = downloadFile($link, $fullDir);
if ($result['success']) {
$fileUrl = $dir . "/" . $result['filename'];
echo "✅ تم التحميل بنجاح<br>";
echo "? تم الحفظ في: " . $result['filepath'] . "<br>";
echo "<a href='$fileUrl' target='_blank'>? فتح الملف</a>";
} else {
echo $result['msg'];
}
echo "<br><br>";
}
}
?>
</center>
</div>
</body>
</html>