Avatar billede coolcom Nybegynder
08. juni 2008 - 14:58 Der er 6 kommentarer

Kan ikke finde fejlen

Hey..

Jeg er ved at lave et billed upload system.
Jeg har følgende kode:

$counter = 0;
   
        // List of our known photo types
        $known_photo_types = array(
                            'image/pjpeg' => 'jpg',
                            'image/jpeg' => 'jpg',
                            'image/gif' => 'gif',
                            'image/bmp' => 'bmp',
                            'image/x-png' => 'png'
                        );
       
        // GD Function List
        $gd_function_suffix = array(
                            'image/pjpeg' => 'JPEG',
                            'image/jpeg' => 'JPEG',
                            'image/gif' => 'GIF',
                            'image/bmp' => 'WBMP',
                            'image/x-png' => 'PNG'
                        );
   
        // Fetch the photo array sent by preupload.php
        $photos_uploaded = $_FILES['photo_filename'];
   
        // Fetch the photo caption array
        $photo_caption        = $_POST['photo_caption'];
        $photo_category    = $_POST['category'];
        $number_of_fields    = $_POST['number_of_fields'];
       
        $path = realpath($_SERVER['DOCUMENT_ROOT']) . $settings['galleryImageDir'];
       
       
        if (empty($photo_category))
            {
                $form_error = $error->form_error($error = 'Du har ikke valgt en kategori');
                $this->upload();
                return;
            }
   
        while( $counter <= count($photos_uploaded) )
        {
            if($photos_uploaded['size'][$counter] > 0)
            {
                if(!array_key_exists($photos_uploaded['type'][$counter], $known_photo_types))
                {
                    $this->output = $error->error('Ugyldig filtype i blandt de uploadede billeder');
                }
                else
                {
                    $connector->query('INSERT INTO cms_gallery_photos SET photo_filename="0", photo_caption="'.addslashes($photo_caption[$counter]).'",
                    photo_category="'.addslashes($_POST['category']).'"');
                   
                    $new_id = mysql_insert_id();
                    $filetype = $photos_uploaded['type'][$counter];
                    $extention = $known_photo_types[$filetype];
                    $filename = $new_id.".".$extention;
   
                    $connector->query('UPDATE cms_gallery_photos SET photo_filename="'.addslashes($filename).'" WHERE photo_id="'.addslashes($new_id).'"');
   
                    // Store the orignal file
                    move_uploaded_file($photos_uploaded['tmp_name'][$counter], $path . $filename);
   
                    // Let's get the Thumbnail size
                    $size = GetImageSize( $path . $filename );
                    if($size[0] > $size[1])
                    {
                        $thumbnail_width = 150;
                        $thumbnail_height = (int)(150 * $size[1] / $size[0]);
                    }
                    else
                    {
                        $thumbnail_width = (int)(150 * $size[0] / $size[1]);
                        $thumbnail_height = 150;
                    }
               
                    // Build Thumbnail with GD 1.x.x, you can use the other described methods too
                    $function_suffix = $gd_function_suffix[$filetype];
                    $function_to_read = "ImageCreateFrom".$function_suffix;
                    $function_to_write = "Image".$function_suffix;
   
                    // Read the source file
                    $source_handle = $function_to_read ( $path . $filename );
                   
                    if($source_handle)
                    {
                        // Let's create an blank image for the thumbnail
                        $destination_handle = imagecreatetruecolor( $thumbnail_width, $thumbnail_height );
                   
                        // Now we resize it
                        imagecopyresampled( $destination_handle, $source_handle, 0, 0, 0, 0, $thumbnail_width, $thumbnail_height, $size[0], $size[1] );
                    }
   
                    // Let's save the thumbnail
                    $function_to_write( $destination_handle, $path."thumbs/tb_".$filename );
                    ImageDestroy($destination_handle );
                    //
                   
                    //Let's make the small images
                    $size = GetImageSize( $path . $filename );
                    if($size[0] > $size[1])
                    {
                        $small_width = 552;
                        $small_height = (int)(552 * $size[1] / $size[0]);
                    }
                    else
                    {
                        $small_width = (int)(552 * $size[0] / $size[1]);
                        $small_height = 552;
                    }
               
                    // Build small with GD 1.x.x, you can use the other described methods too
                    $function_suffix = $gd_function_suffix[$filetype];
                    $function_to_read = "ImageCreateFrom".$function_suffix;
                    $function_to_write = "Image".$function_suffix;
   
                    // Read the source file
                    $source_handle = $function_to_read ( $path . $filename );
                   
                    if($source_handle)
                    {
                        // Let's create an blank image for the small
                        $destination_handle = imagecreatetruecolor( $small_width, $small_height );
                   
                        // Now we resize it
                        imagecopyresampled( $destination_handle, $source_handle, 0, 0, 0, 0, $small_width, $small_height, $size[0], $size[1] );
                    }
   
                    // Let's save the small
                    $function_to_write( $destination_handle, $path."small/s_".$filename );
                    ImageDestroy($destination_handle );
                   
                   
                   
                    $result_final .= "<img src='".$path."tb_".$filename."' /> File ".($counter+1)." Added<br />";
                    $this->output = $this->html->add_complete($result_final);
                }
            }
        $counter++;
        }


Når jeg uploader et billed, vil jeg have den til at lave et thumbnail, et "small" billed på 552 px, samt at gemme det originale billed.

Når jeg så prøver at uploade et af de store, gemmer den det originale og et thumbnail. Men "small" billedet fejler.
Jeg har prøvet at kigge på koden men jeg kan ikke lige finde fejlen, så jeg håber du/i kan.
Avatar billede w13 Novice
09. juni 2008 - 11:37 #1
Hvordan fejler small billedet?
Avatar billede coolcom Nybegynder
09. juni 2008 - 13:19 #2
Det bliver ikke lavet. Orgiginal billedet og thumbnailen bliver overført korrekt, men ikke "small-billedet"
Avatar billede coolcom Nybegynder
10. juni 2008 - 22:03 #3
Er der ingen der kan hjælpe mig??
Avatar billede jakobdo Ekspert
10. juni 2008 - 22:07 #4
Overvej at brug mine artikler, de virker hver gang.
Avatar billede coolcom Nybegynder
11. juni 2008 - 00:20 #5
Det har jeg prøvet.

http://www.eksperten.dk/artikler/1200

Det er denne jeg har brugt, men der fik jeg en fejl om at den ikke kunne resize billedet.

Jeg tror lige du skal kigge koden igennem en gang til. Jeg har i hvert bare kopieret direkte over og lavet en mappe samme sted ved navn upload og en mappe inde i den med navnet thumbs. Og dette virker ikke.

Jeg håber du kan hjælpe mig
Avatar billede jakobdo Ekspert
11. juni 2008 - 06:31 #6
Og du har husket at chmod'e som der står ?
Jeg har selv testet koden og den virker helt fint.
Så måske du skal kigge koden igennem. :o)
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Vi tilbyder markedets bedste kurser inden for webudvikling

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester