Jump to content

Archived

This topic is now archived and is closed to further replies.

Immortal55

Gallery Script Help

Recommended Posts

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:
[code]
<?
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;
?>
[/code]

and artupload.php
[code]
<?

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);
?>
[/code]

what is wrong?? thank you.

Share this post


Link to post
Share on other sites
OK.

In the artupload file you have this....[code]<?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
}

...
?>

[/code]

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

Share this post


Link to post
Share on other sites
alright, i added all that but now i am getting this warning:

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

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.