par
sabreofthewind » 20 juin 2013, 06:09
bonjour tout le monde,
mon problème c'est que je veux uploader des fichiers a partir de mon site web vers jheberg puis récupérer la réponse du serveur pour mettre tout dans une BDD .Voici mon code :
le formulaire :
<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>
le manipulateur :
<?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";
$postData = array('file' => '@'.$_FILES["file"]["tmp_name"], '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);
// Afficher les résultat
var_dump($data);
}
}
}
else
{
echo "Invalid file";
}
?>
Résultat d'affichage pour $data = NULL
Si vous pouvez m'aider je serais très reconnaissant.
Cordialement.
bonjour tout le monde,
mon problème c'est que je veux uploader des fichiers a partir de mon site web vers jheberg puis récupérer la réponse du serveur pour mettre tout dans une BDD .Voici mon code :
le formulaire :
[php]<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]
le manipulateur :
[php]<?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";
$postData = array('file' => '@'.$_FILES["file"]["tmp_name"], '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);
// Afficher les résultat
var_dump($data);
}
}
}
else
{
echo "Invalid file";
}
?>[/php]
Résultat d'affichage pour $data = NULL
Si vous pouvez m'aider je serais très reconnaissant.
Cordialement.