Bluntch | Bonjour bonjour,
j'ai un soucis dans mon script, j'utilise SWF upload :
http://demo.swfupload.org/applicationdemo/index.php
c'est le upload.php le bug ce trouve sans doute au niveau de la fusion des images mais je ne sais pas pourquoi ! et j'aimerai enregistré l'image dans un fichier mais je voi pas comment :s!
Code :
- <?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();
- // Check the upload
- if (!isset($_FILES["Filedata"]) || !is_uploaded_file($_FILES["Filedata"]["tmp_name"]) || $_FILES["Filedata"]["error"] != 0) {
- header("HTTP/1.1 500 Internal Server Error" );
- echo "invalid upload";
- exit(0);
- }
- // Get the image and create a thumbnail
- $img = @imagecreatefromjpeg($_FILES["Filedata"]["tmp_name"]);
- if (!$img) {
- header("HTTP/1.1 500 Internal Server Error" );
- echo "could not create image handle";
- exit(0);
- }
- $width = imageSX($img);
- $height = imageSY($img);
- if (!$width || !$height) {
- header("HTTP/1.1 500 Internal Server Error" );
- echo "Invalid width or height";
- exit(0);
- }
- // Build the big tof
- $target_width = 700;
- $target_height = 700;
- $target_ratio = $target_width / $target_height;
- $img_ratio = $width / $height;
- if ($target_ratio > $img_ratio) {
- $new_height = $target_height;
- $new_width = $img_ratio * $target_height;
- } else {
- $new_height = $target_width / $img_ratio;
- $new_width = $target_width;
- }
- if ($new_height > $target_height) {
- $new_height = $target_height;
- }
- if ($new_width > $target_width) {
- $new_height = $target_width;
- }
- $new_img = ImageCreateTrueColor($target_width, $target_height);
- if (!@imagefilledrectangle($new_img, 0, 0, $target_width-1, $target_height-1, 0)) { // Fill the image black
- header("HTTP/1.1 500 Internal Server Error" );
- echo "Could not fill new image";
- exit(0);
- }
- if (!@imagecopyresampled($new_img, $img, ($target_width-$new_width)/2, ($target_height-$new_height)/2, 0, 0, $new_width, $new_height, $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();
- }
- // On charge d'abord les images
- $source = imagecreatefrompng("images/logo_tof.png" ); // Le logo est la source
- //$destination = imagecreatefromjpeg("test.jpg" ); // La photo est la destination
- // Les fonctions imagesx et imagesy renvoient la largeur et la hauteur d'une image
- $largeur_source = imagesx($source);
- $hauteur_source = imagesy($source);
- $largeur_destination = imagesx($new_img);
- $hauteur_destination = imagesy($new_img);
- // On veut placer le logo en bas à droite, on calcule les coordonnées où on doit placer le logo sur la photo
- $destination_x = $largeur_destination - $largeur_source;
- $destination_y = $hauteur_destination - $hauteur_source;
- // On met le logo (source) dans l'image de destination (la photo)
- if (!@imagecopymerge($new_img, $source, $destination_x, $destination_y, 0, 0, $largeur_source, $hauteur_source, 60);
- header("HTTP/1.0 500 Internal Server Error" );
- echo "Could not merge image";
- exit(0);
- }
- // Use a output buffering to load the image into a variable
- ob_start();
- imagejpeg($new_img);
- $new_img = ob_get_contents();
- ob_end_clean();
- $file_id2 = md5($_FILES["Filedata"]["tmp_name"] + rand()*100000);
- $_SESSION["file_info"][$file_id2] = $new_img;
- echo $file_id2; // Return the file id to the script
- ?>
|
|