Fortfarande id till bild...:(
Fick den här koden av en snäll person som ville dela med sig...
Jag förstår att koden inte är komplett, och att den dessutom skapar thumbs vilket ju är trevligt ;)
Men jag måste deklarera $method nånstans eller?
Sen är jag inte säker på vilka nödvändiga databasfält jag måste ha.. förutom id, userfile o name...
Nån som vill hjälpa mig?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | <? function resize_image( $image , $dest_x_max , $dest_y_max , $jpeg_qual ) { $image_id = imagecreatefromjpeg( $image ); $image_x = imagesx( $image_id ); $image_y = imagesy( $image_id ); if ( $image_x > $dest_x_max || $image_y > $dest_y_max ) { if ( $image_x > $image_y ) { $dest_x = $dest_x_max ; $dest_y = $image_y * ( $dest_x_max / $image_x ); } else { $dest_y = $dest_y_max ; $dest_x = $image_x * ( $dest_y_max / $image_y ); } $newimage_id = ImageCreateTrueColor( $dest_x , $dest_y ); $newimage = ImageCopyResampled( $newimage_id , $image_id , 0, 0, 0, 0, $dest_x , $dest_y , $image_x , $image_y ); $image .= "_thumb" ; imagejpeg( $newimage_id , $image , $jpeg_qual ); imagedestroy( $newimage_id ); } else { $newimage = copy ( $image , $image . '_thumb' ); } return $newimage ; } ?> <html> <head> <title>Ladda upp</title> </head> <body> <? echo "<table>" ; echo "<tr><td colspan='2'><form action='laddaupp.php' method='POST' enctype='multipart/form-data'>" ; echo "<tr><td colspan='2'><input name=\"userfile1\" type=\"file\" style=\"width:300px\" value=\"Bläddra..\"></td></tr>\n" ; echo "<tr><td colspan='2'><input name=\"userfile2\" type=\"file\" style=\"width:300px\" value=\"Bläddra..\"></td></tr>\n" ; echo "<tr><td colspan='2'><input name='submit' type='button' value='Ladda upp'></td></tr>\n" ; echo "</form></table>" ; ?> <? if ( $method == 1) { $simage = mysql_insert_id(); } else { $simage = $_POST [ 'id' ]; } $simage = $_POST [ 'id' ]; for ( $i =1; $i <=4; $i ++) { if ( is_uploaded_file ( $_FILES [ 'userfile' . $i ][ 'tmp_name' ])) { // Fixa lower case, Inga '$', Inga mellanslag $_FILES [ 'userfile' . $i ][ 'name' ] = strtolower ( $_FILES [ 'userfile' . $i ][ 'name' ]); $_FILES [ 'userfile' . $i ][ 'name' ] = str_replace ( ' ' , '_' , $_FILES [ 'userfile' . $i ][ 'name' ]); $_FILES [ 'userfile' . $i ][ 'name' ] = str_replace ( '$' , '_' , $_FILES [ 'userfile' . $i ][ 'name' ]); if (! is_dir ( '/ny/bilder/' . $simage . "/" )) { mkdir ( '/ny/bilder/' . $simage ). "/" ; chmod ( '/ny/bilder/' . $simage , 0777); } move_uploaded_file( $_FILES [ 'userfile' . $i ][ 'tmp_name' ], '/ny/bilder/' . $simage . "/" . $_FILES [ 'userfile' . $i ][ 'name' ]); $image = '/ny/bilder/' . $simage . "/" . $_FILES [ 'userfile' . $i ][ 'name' ]; $thumb = resize_image( $image , 100, 100, 90); } } ?> |
Svara