L'upload se passe dans le fichier upload.php :
Je te copie le mien, qui fait un upload de fichier (des photos dans mon cas), et qui en fait un thumbnail (miniatures) qu'il copie dans un dossier propre au thumbnails.
Lis le, comprends le, et arranges le à ta sauce. Mais comme je te l'ai dit, pas facile à mettre en place la première fois. Prend bien la dernière version en date (2.2.0 Beta 3), elle corrige des bugs et est plus facile à mettre en place il me semble. N'hésites pas à te tourner vers la doc présente sur le site.
N'hésites pas non plus à m'envoyer un message privé, si tu as des problèmes.
<?php
require_once '../connexion.php';
require_once '../vars.php';
require_once '../functions.php';
/* Note: This thumbnail creation script requires the GD PHP Extension.
If GD is not installed correctly PHP does not render this page correctly
and SWFUpload will get "stuck" never calling uploadSuccess or uploadError
*/
// Get the session Id passed from SWFUpload. We have to do this to work-around the Flash Player Cookie Bug
if (isset($_POST["PHPSESSID"])) {
session_id($_POST["PHPSESSID"]);
}
session_start();
ini_set("html_errors", "0");
// Check the upload
if (!isset($_FILES["Filedata"]) || !is_uploaded_file($_FILES["Filedata"]["tmp_name"]) || $_FILES["Filedata"]["error"] != 0) {
echo "ERROR:invalid upload";
exit(0);
}
// Get the image and create a thumbnail
$img = imagecreatefromjpeg($_FILES["Filedata"]["tmp_name"]);
if (!$img) {
echo "ERROR:could not create image handle ". $_FILES["Filedata"]["tmp_name"];
exit(0);
}
$width = imageSX($img);
$height = imageSY($img);
if (!$width || !$height) {
echo "ERROR:Invalid width or height";
exit(0);
}
// Build the thumbnail
$thumbHeight = 90;
$thumbWidth = round($width * $thumbHeight / $height);
$new_img = imagecreatetruecolor($thumbWidth, $thumbHeight);
if (!@imagecopyresampled($new_img, $img, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $width, $height)) {
header("HTTP/1.0 500 Internal Server Error");
echo "Could not resize image";
exit(0);
}
if (!isset($_SESSION["file_info"])) {
$_SESSION["file_info"] = array();
}
// Use a output buffering to load the image into a variable
/*
ob_start();
imagejpeg($new_img);
$imagevariable = ob_get_contents();
ob_end_clean();
$file_id = md5($_FILES["Filedata"]["tmp_name"] + rand()*100000);
$_SESSION["file_info"][$file_id] = $imagevariable;
*/
/////////////////////////////////////////////////////////////////////////////////////////////
// On fait l'upload ici, car si on le fait avant la création des thumbnails, le script bug //
/////////////////////////////////////////////////////////////////////////////////////////////
// Ajout dans la BDD
$photo_id = updateTableAndGetInsertId("INSERT INTO ".$cfg_prefixe."photos VALUES('', '".$_POST['ANNONCE_ID']."', '".date('Y-m-d H:i:s')."', '')");
$extension = strtolower(strrchr($_FILES["Filedata"]["name"],'.'));
$pathLarges = '../medias/photos/larges/';
$pathThumbs = '../medias/photos/thumbs/';
$photoName = $_POST['ANNONCE_ID'].'_'.$photo_id;
// upload de l'image
move_uploaded_file($_FILES["Filedata"]["tmp_name"], $pathLarges.$photoName.$extension);
// On la rétrécie si trop grande
if($height > 400)
createThumbnail($photoName.$extension, $extension, $pathLarges, $pathLarges, 400);
// enregistrement du thumb
createThumbnail($photoName.$extension, $extension, $pathLarges, $pathThumbs, 90);
/////////////////////////////////////////////////////////////////////////////////////////////
// Fin de l'upload //
/////////////////////////////////////////////////////////////////////////////////////////////
//echo "FILEID:" . $file_id; // Return the file id to the script
echo "FILEID:".$photoName;
?>