Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

Lesson 9 of DW CS5 & PHP Training from source problem

Explorer ,
Jun 29, 2011 Jun 29, 2011

Copy link to clipboard

Copied

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.

TOPICS
Server side applications

Views

473
Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 29, 2011 Jun 29, 2011

Copy link to clipboard

Copied

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.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 30, 2011 Jun 30, 2011

Copy link to clipboard

Copied

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

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 30, 2011 Jun 30, 2011

Copy link to clipboard

Copied

LATEST

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

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines