Skip to main content
Inspiring
June 29, 2011
Question

Lesson 9 of DW CS5 & PHP Training from source problem

  • June 29, 2011
  • 2 replies
  • 498 views

Page 315.  Supposed to show name of file uploaded after inserting code for $filename.  The $filename is never shown.  How can I check to see that the $messages[] is set, and how can I trace the problem? Result SHOULD be that the message "filename successfully uploaded" where filename is the name of the file.   Code follows:

process_upload.php:

<?php
if (isset($_POST['upload'])) {
    require_once('library.php');
    try {
        $destination = 'C:/upload_test';
        $uploader = new Zend_File_Transfer_Adapter_Http();
        $uploader->setDestination($destination);
        $success = $uploader->receive();
        if (!$success) {
            $messages = $uploader->getMessages();
        } else{
            $filename = $uploader->getFileName(NULL, FALSE);
            $MESSAGES[] = "$filename uploaded successfully";
        }
    } catch (Exception $e) {
        echo $e->getMessage();
    }
}


upload_test.php:

<?php
require_once('scripts/process_upload.php');
?>
<!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=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php
if (isset($messages)) {
    echo '<ul>';
    foreach ($messages as $item) {
        echo "<li>$item</li>";
    }
    echo '</ul>';
}
?>
<form action"" method="post" enctype = "multipart/form-data" name="form1" id="form1">
  <p>
    <input name="MAX_FILE_SIZE" type="hidden" id="MAX_FILE_SIZE" value="51200" />
    <label for="upload_file">File to upload</label>
    <input type="file" name="upload_file" id="upload_file" />
  </p>
  <p>
    <input type="submit" name="upload" id="upload" value="Upload File" />
  </p>
</form>
</body>
</html>

For the life of me, I can not figure out why the message that the file uploaded successfully isn't displayed.

This topic has been closed for replies.

2 replies

David_Powers
Inspiring
June 30, 2011

Glad you sorted it, Gene. I'm marking this as assumed answered.

Inspiring
July 1, 2011

Absolutely. BTW... I'm loving this book. One of the things I have on my plate right now is designing a dedicated upload section for a client. They need to have an area where their clients can upload files - images, pdf files, powerpoint displays, you name it, they have to be able to accept them. Chapter 9 is giving me the background to develop the utility they need.

Gene

Inspiring
June 29, 2011

Duh!  I knew as soon as I posted this I'd figure it out.

  $MESSAGES[] = "$filename uploaded successfully"; needs to be $messages[] = "$filename uploaded successfully".  I must have hit the caps key by accident there, and never noticed it.

Working right now.