Jump to content

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.
Link to comment
https://forums.phpfreaks.com/topic/5965-gallery-script-help/
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
Link to comment
https://forums.phpfreaks.com/topic/5965-gallery-script-help/#findComment-21411
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.