Jump to content


Photo

Gallery Script Help


  • Please log in to reply
4 replies to this topic

#1 Immortal55

Immortal55
  • Members
  • PipPipPip
  • Advanced Member
  • 59 posts

Posted 27 March 2006 - 09:46 PM

I am working on a gallery, I got it from a tutorial, and i am tweaking it but after i select my photos and press the submit button it just sits there loading and nothing happens and then i get this error message:

Fatal error: Maximum execution time of 30 seconds exceeded in /home/.diddle/studiocommunity/studiocommunity.net/artupload.php on line 65

here are the scripts

artuploadforms.php:
<?
include 'image.dbconnect.php';

 // initialization
 $photo_upload_fields = '';
 $counter = 1;

 // If we want more fields, then use, preupload.php?number_of_fields=20
 $number_of_fields = (isset($_GET['number_of_fields'])) ?
   (int)($_GET['number_of_fields']) : 5;

 // Firstly Lets build the Category List
 $result = mysql_query('SELECT category_id,category_name FROM art_category');
 while($row = mysql_fetch_array($result)) {
   $photo_category_list .= <<<__HTML_END
<option value="$row">$row</option>\n
__HTML_END;
 }
 mysql_free_result($result);  

 // Lets build the Image Uploading fields
 while($counter <= $number_of_fields) {
   $photo_upload_fields .= <<<__HTML_END
<tr><td>
 Photo {$counter}:
 <input name="photo_filename"
type="file" />
</td></tr>
<tr><td>
 Caption:
 <textarea name="photo_caption" cols="30"
   rows="1"></textarea>
</td></tr>
__HTML_END;
   $counter++;
 }

 // Final Output
 echo <<<__HTML_END
<html>
<head>
<title>Lets upload Photos</title>
</head>
<body>
<form enctype="multipart/form-data"
 action="artupload.php" method="post"
 name="upload_form">
 <table width="90%" border="0"
   align="center" style="width: 90%;">
   <tr><td>
     Select Category
     <select name="category">
     $photo_category_list
     </select>
   </td></tr>
   <!—Insert the image fields here -->
   $photo_upload_fields
   <tr><td>
     <input type="submit" name="submit"
       value="Add Photos" />
   </td></tr>
 </table>
</form>
</body>
</html>
__HTML_END;
?>

and artupload.php
<?

 include ('image.dbconnect.php');

// Fetch the image array sent by preupload.php

$photos_uploaded = $_FILES['photo_filename'];

// Fetch the image caption array

$photo_captions = $_POST['photo_captions'];

$photo_types = array(  
 'image/pjpeg' => 'jpg',
 'image/jpeg' => 'jpg',
 'image/gif' => 'gif',
 'image/bmp' => 'bmp',
 'image/x-png' => 'png'
);

while($counter <= count($photos_uploaded)) {
 if($photos_uploaded['size'][$counter] > 0) {
   if(!array_key_exists($photos_uploaded['type'][$counter], $photo_types)) {
     $result_final .= 'File ' . ($counter + 1) .
       ' is not a photo<br />';
   } else {
     // Great the file is an image, we will add this file
   }
 }
}

mysql_query("
 INSERT INTO art_photos 
 (photo_filename, photo_caption, photo_category) VALUES 
 ('0', '" . $photo_captions[$counter]) . "', '" . $_POST['category'] . "')'";


$new_id = mysql_insert_id(); // New Id generated

// Get the filetype of the uploaded file
$filetype = $photos_uploaded['type'][$counter];  

// Get the extension for the new name
$extension = $known_photo_types[$filetype];  

// Generate a new name
$filename = "$new_id.$extension";  

// let’s update the filename now
mysql_query("
 UPDATE gallery_photos SET
   photo_filename = '$filename'
 WHERE photo_id = '$new_id'
");

copy($photos_uploaded['tmp_name'][$counter],
 $images_dir . '/' . $filename);
 
 move_uploaded_file($photos_uploaded['tmp_name'][$counter],
 $images_dir . '/' . $filename);
?>

what is wrong?? thank you.

#2 Immortal55

Immortal55
  • Members
  • PipPipPip
  • Advanced Member
  • 59 posts

Posted 28 March 2006 - 12:56 AM

anyone? help, please.

#3 ToonMariner

ToonMariner
  • Members
  • PipPipPip
  • Advanced Member
  • 3,342 posts
  • LocationNewcastle upon Tyne, UK

Posted 28 March 2006 - 01:10 AM

OK.

In the artupload file you have this....
<?php

.......
$counter = 0; //ADD THIS LINE.
while($counter <= count($photos_uploaded)) {
if($photos_uploaded['size'][$counter] > 0) {
   if(!array_key_exists($photos_uploaded['type'][$counter], $photo_types)) {
     $result_final .= 'File ' . ($counter + 1) .
       ' is not a photo<br />';
   } else {
     // Great the file is an image, we will add this file
   }
}
$counter++; //ADD THIS LINE
}

...
?>


you still need anotehr loop to copy all teh files (it looks to me that you will only actually do one upload completely with script) but that is for you to throw and catch

follow me on twitter @PHPsycho

#4 Immortal55

Immortal55
  • Members
  • PipPipPip
  • Advanced Member
  • 59 posts

Posted 28 March 2006 - 02:21 AM

alright, i added all that but now i am getting this warning:


Warning: copy(h): failed to open stream: No such file or directory in /home/.diddle/studiocommunity/studiocommunity.net/artupload.php on line 102


#5 Immortal55

Immortal55
  • Members
  • PipPipPip
  • Advanced Member
  • 59 posts

Posted 28 March 2006 - 06:47 AM

i still cannot get it, does anybody have any ideas?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users