Jeg bruger koden nedenfor til at uploade billeder med. Men jeg har et lille problem. Jeg kan nemt uploade ét stort billede: 2496 x 2331 - 4.9 MB men da det jo er et multi-billede-upload script så skal det jo være muligt for brugeren at uploade flere billeder. Lad os side at $felter = 20. Så prøver jeg at uploade 20 af de store billeder og får fejlen:
Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate xxxx bytes) in /some/location/upload.php on line 149
Linje 149:- $source_handle = $function_to_read ( $images_dir."/".$filename );
upload.php- <?php
- include("config.inc.php");
-
- // initialization
- $result_final = "";
- $counter = 0;
-
- // List of our known photo types
- $known_photo_types = array(
- 'image/pjpeg' => 'jpg',
- 'image/jpeg' => 'jpg',
- 'image/gif' => 'gif',
- 'image/x-png' => 'png'
- );
-
- // GD Function List
- $gd_function_suffix = array(
- 'image/pjpeg' => 'JPEG',
- 'image/jpeg' => 'JPEG',
- 'image/gif' => 'GIF',
- 'image/x-png' => 'PNG'
- );
- if(isset($_POST['felter'])) {
- $felter = $_POST['felter'];
- }
-
- for($x=0;$x<=$felter;$x++){
-
- // Fetch the photo array sent by preupload.php
- $photos_uploaded = $_FILES['photo_filename'. $x];
-
- // Fetch the photo caption array
- $photo_caption = $_POST['photo_caption'. $x];
-
-
- if($photos_uploaded['size'] > 0)
- {
- if(!array_key_exists($photos_uploaded['type'], $known_photo_types))
- {
- $result_final .= "<div class='alm'>Fil ".($x+1)." kan ikke uploades. Der må kun uploades .jpg, .jpeg, .gif og .png filer</div><br />";
- }
- else
- {
- mysql_query( "INSERT INTO gallery_photos(`photo_filename`, `photo_caption`, `photo_category`, `bruger`) VALUES('0', '".addslashes($photo_caption)."', '".addslashes($_POST['category'])."', '". $_POST['bruger'] ."')" );
- $new_id = mysql_insert_id();
- $filetype = $photos_uploaded['type'];
- $extention = $known_photo_types[$filetype];
- $filename = $new_id.".".$extention;
-
- mysql_query( "UPDATE gallery_photos SET photo_filename='".addslashes($filename)."' WHERE photo_id='".addslashes($new_id)."'" );
-
- // Store the orignal file
- copy($photos_uploaded['tmp_name'], $images_dir."/".$filename);
-
- // Let's get the Thumbnail size
- $size = GetImageSize( $images_dir."/".$filename );
- if($size[0] > $size[1])
- {
- $thumbnail_width = 100;
- $thumbnail_height = (int)(100 * ($size[1] / $size[0]));
- }
- else
- {
- $thumbnail_width = (int)(100 * ($size[0] / $size[1]));
- $thumbnail_height = 100;
- }
-
- mysql_query( "UPDATE gallery_photos SET hojde='".$size[1]."', bredde='".$size[0]."' WHERE photo_id='".addslashes($new_id)."'" );
-
- // 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 ( $images_dir."/".$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, $images_dir."/tb/tb_".$filename );
- ImageDestroy($destination_handle );
- //
-
- $result_final .= "<img src='".$images_dir. "/tb/tb_".$filename."' /> <div class='alm'>Billede ".($x+1)." blev uploadet</div><br />";
- }
- }
-
- }
-
- ?>
Hvis nødvendigt:
preupload.php- <?php
-
- if(isset($_POST['felter'])) {
- $felter = $_POST['felter'];
- }
-
- include("config.inc.php");
-
- // initialization
- $photo_upload_fields = "";
- $counter = 1;
-
- // default number of fields
- $number_of_fields = $felter;
-
- // If you want more fields, then the call to this page should be like,
- // preupload.php?number_of_fields=20
-
- if( $_GET['number_of_fields'] )
- $number_of_fields = (int)($_GET['number_of_fields']);
-
- $result = mysql_query( "SELECT category_id,category_name FROM gallery_category" );
- while( $row = mysql_fetch_array( $result ) )
- {
- $photo_category_list .=<<<__HTML_END
- <option value="$row[0]">$row[1]</option>\n
- __HTML_END;
- }
- mysql_free_result( $result );
-
- // Lets build the Photo Uploading fields
- for($x=0;$x<$felter;$x++){
- $nyx = $x +1;
- $photo_upload_fields .=<<<__HTML_END
- <tr>
- <td class="alm">
- Billede {$nyx}:
- <input class="TextField" name='photo_filename$x' id='photo_filename$x' type='file' />
- </td>
- </tr>
- <tr>
- <td class="alm">
- Beskrivelse:
- <textarea class="TextField" name='photo_caption$x' id='photo_caption$x' cols='40' rows='3'></textarea>
- </td>
- </tr>
- __HTML_END;
- }
- ?>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
- <title>SimpleWeb CMS - Administration - Galleri</title>
- <link rel="StyleSheet" href="../style.css" type="text/css">
- <style type="text/css">
- <!--
- body {
- background-image: url(../images/bg.jpg);
- }
- a:link {
- color: #FFFFFF;
- text-decoration: none;
- }
- a:visited {
- text-decoration: none;
- color: #FFFFFF;
- }
- a:hover {
- text-decoration: none;
- color: #FFFFFF;
- }
- a:active {
- text-decoration: none;
- color: #FFFFFF;
- }
- -->
- </style></head>
-
- <body>
- <table width="100%" border="0" bgcolor="#1B8DCF">
- <tr>
- <td width="25%" valign="top" class="alm"><strong><a href="galleri.php">Se albummerne</a></strong></td>
- <td width="50%" valign="top"><div align="center" class="alm"><strong><a href="nytalbum.php">Opret album</a> | <a href="hvormangefelter.php">Upload billeder</a></strong> | <strong><a href="redigeralbum.php">Rediger navn på album</a></strong></div></td>
- <td width="25%" valign="top"><div align="right" class="alm"><a href="<?php echo $logoutAction ?>" class="alm"><strong>Log ud</strong></a><br />
- <?php echo 'Du er logget ind som: '. $_SESSION['MM_Username'] .''; ?></div>
- <br /></td>
- </tr>
- <tr>
- <td colspan="3"><table width="385" border="0">
- <tr>
- <td colspan="2"><span class="alm"><strong>Opret et nyt album:<br />
- <br />
- <strong> Du kan downloade et gratis billed-resize <br />
- program <a href="http://www.vso-software.fr/products/image_resizer/"><u>her</u></a>, da nogle billeder kan være for store.</strong></strong><br />
- </span></td>
- </tr>
- <form enctype='multipart/form-data' action='upload.php' method='post' name='upload_form'>
- <tr>
- <td width="237" valign="top" class="alm">Vælg et album:
- <select class="TextField" name='category'>
- <?php echo ''. $photo_category_list. ''; ?>
- </select>
- <br />
- <br /></td>
- <td width="138"><br />
- <?php echo ''. $photo_upload_fields .''; ?></td></tr>
-
- <tr>
- <td><input type="submit" name="button" id="button" value="Opret" class="TextField" />
- <input type="hidden" name="bruger" id="bruger" value="<?php echo $_SESSION['MM_Username']; ?>" /><input name="felter" type="hidden" value="<? echo $felter; ?>"></td>
- <td> </td>
- </tr>
- </form>
- </table>
- <br /></td>
- <tr>
- </table>
- </body>
- </html>
Hvad gør jeg forkert??
Indlæg senest redigeret d. 28.12.2008 01:27 af Bruger #14535