السلام عليكم
أخوتي في الله ، أريد مساعدة منكم في سكريبت جزاكم الله خيرا
السكريبت يرفع ملفات مستخدمي موقعي مباشرة إلى سيرفر jheberg المشكل هو كيفية استرجاع إجابة السيرفر (json) لوضعها في قاعدة للبيانات
السكريبت :
<html> <body> <form action="2.php" method="post" enctype="multipart/form-data"> <label for="file">Filename:</label> <input type="file" name="file" id="file"><br> <input type="submit" name="submit" value="Submit"> </form> </body> </html>
<?php
$allowedExts = array("gif", "jpeg", "jpg", "png");
$extension = end(explode(".", $_FILES["file"]["name"]));
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/jpg")
|| ($_FILES["file"]["type"] == "image/pjpeg")
|| ($_FILES["file"]["type"] == "image/x-png")
|| ($_FILES["file"]["type"] == "image/png"))
&& ($_FILES["file"]["size"] < 20000)
&& in_array($extension, $allowedExts))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
}
else
{
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>";
if (file_exists("upload/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
$url = 'http://zoidberg.jheberg.net/jheberg/index.php?method=apiUpload';
/******************************************/
/* Envoie du fichier */
/******************************************/
$postData = array('file' => '@'.realpath($file), 'username' => false, 'password' => false);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
$data = curl_exec($ch);
curl_close($ch);
$data = json_decode($data, true);
// Afficher les résultat
var_dump($data);
}
}
}
else
{
echo "Invalid file";
}
?>السكريبت يعطي إجابة data = null