Lesson 9 of DW CS5 & PHP Training from source problem
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.
