Help a newbie please?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dragonscrapsit
Forum Newbie
Posts: 2
Joined: Mon Mar 24, 2014 6:22 pm

Help a newbie please?

Post by dragonscrapsit »

I am new to PHP and I am having some problems and I am hoping someone can point me in the right direction. Here is what I need to do:

Create a Web Form for uploading pictures for a high school reunion. The form should have text input fields for the person's name and a description of the image, and a file input field for the image. To accompany each file, create a text file that contains the name and description of the image. Create a separate Web Page that displays the pictures with a caption showing the name and description fields. Make sure the folder has read and write for everyone.

Here is what I have but it isnt working properly:

Code: Select all

<html>
<head>
<body>
<form action="" method="post" enctype="multipart/form-data"name="uploadImage" id="uploadImage">

<p><input type="text" name="name of person" value="name" size="20"/> 

<input type="hidden" name="MAX_FILE_SIZE" value="<?php echo MAX_FILE_SIZE; ?>" />
  
  <label for="image">Upload image:</label>
  
  <input type="file" name="image" value="name and description" id="image" />

  </p>
<p>
  <input type="submit" name="upload" id="upload" 
value="Upload" />
</p>
</form></body></head></html>

<?php

define ('MAX_FILE_SIZE', 1024 * 50);

if (array_key_exists('upload', $_POST)) {

  define('UPLOAD_DIR', '/path/to/images/');

  $file = str_replace(' ', '_', $_FILES['image']['name']);

  $permitted = array('image/gif', 'image/jpeg', 'image/pjpeg',
'image/png');

  if (in_array($_FILES['image']['type'], $permitted)
      && $_FILES['image']['size'] > 0 
      && $_FILES['image']['size'] <= MAX_FILE_SIZE) {
    switch($_FILES['image']['error']) {
      case 0:

        if (!file_exists(UPLOAD_DIR . $file)) {

          $success =
move_uploaded_file($_FILES['image']['tmp_name'], UPLOAD_DIR .
$file);
        } else {
          $result = 'A file of the same name already exists.';
        }
        if ($success) {
          $result = "$file uploaded successfully.";
        } else {
          $result = "Error uploading $file. Please try again.";
        }
        break;
      case 3:
      case 6:
      case 7:
      case 8:
        $result = "Error uploading $file. Please try again.";
        break;
      case 4:
        $result = "You didn't select a file to be uploaded.";
    }
  } else {
    $result = "$file is either too big or not an image.";
  }
}
?>
Error: Notice: Use of undefined constant MAX_FILE_SIZE - assumed 'MAX_FILE_SIZE' in C:\wamp\www\test.php on line 8 Call Stack #TimeMemoryFunctionLocation 10.0005691592{main}( )..\test.php:0 MAX_FILE_SIZE" />

Anyone have any ideas? Any help is greatly appreciated!
dragonscrapsit
Forum Newbie
Posts: 2
Joined: Mon Mar 24, 2014 6:22 pm

Re: Help a newbie please?

Post by dragonscrapsit »

<input type="hidden" name="MAX_FILE_SIZE" value="<?php echo MAX_FILE_SIZE; ?>" /> I found out my error code.

Now that I have this working so that it uploads, How can I achieve the second part by Create a separate Web Page that displays the pictures with a caption showing the name and description fields?
Post Reply