Copy link to clipboard
Copied
I am tyring to use the Zend Framework to upload files as outlined in the "Adobe Dreamweaver CS5 with PHP" book by David Powers. I've been using the example code (more or less), and can get it to work perfectly with a local XAMPP installation of Apache and PHP. Howver, I can't get it to work successfully with a hosted site, having tried both GoDaddy and Verio.
The Zend Framework is correctly installed, include paths set correctly (I know this because other Zend FW operations, such as validation work fine). In addition, if the directory I want to upload to isn't correctly specified I get errors on that. But when I try to actually upload a file (again, with code that works on the XAMPP platform), I get nothing. No errors, and no uploaded file.
I have the script set up to send an email with a link to the uploaded file, and the name field is blank (but the email does get sent, again indicating that the ZF is working). I'm concluding I have something incorrectly configured on the hosting plaforms, and am looking for suggestions as what to look at. Thanks.
BTW, checked the permissions on the upload directory, and it should be writeable...
1 Correct answer
No problems. It's a mistake we've all made at one time or another. Glad you find the book useful.
Copy link to clipboard
Copied
Have you checked the configuration on the remote server? Is file_uploads On?
Copy link to clipboard
Copied
David,
Thanks for the reply. I neglected to mention that file upload do work on the server, it's just the Zend FW implementation that doesn't. The Zend FW is basically what is in your book, and nothing happens when I try an upload, but I know that the code is talking to the FW (e.g., if I provide an invalid path, I get the appropraite PHP error). If I don't use the FW it works. So the following code correctly uploads a file on the hosting platform:
if ($_POST['send']) {
//validate the user input
$val = new Zend_Validate_Alnum(TRUE);
if (!$val->isValid($_POST['name'])) {
$errors['name'] = 'Name is required';
}
$val = new Zend_Validate_EmailAddress();
if (!$val->isValid($_POST['email'])) {
$errors['email'] = 'Email address is required';
}
$val = new Zend_Validate_StringLength(10);
if (!$val->isValid($_POST['message'])) {
$errors['message'] = 'Required';
}
if (!$errors) {
foreach($_FILES as $temp_name => $file_array) {
$file_name = str_replace(" ","_",$file_array["name"]);
if (is_uploaded_file($file_array["tmp_name"])) {
move_uploaded_file($file_array["tmp_name"], "$file_dir/".$file_name) or die ("Couldn't copy");
}
$new_names[] = $file_name;
}
//start building the mail string
$msg = "Name:\n\t\t".$_POST["name"]."\n";
$msg .= "E-Mail:\n\t\t".$_POST["email"]."\n";
$msg .= "Message:\n\t\t".$_POST["message"]."\n";
foreach ($new_names as $name) {
if ($name != "") {
$msg .= "Link: xxx/uploads/$name"."\n\n";
Using this code I wil email that contains links to the uploaded files, which I can then sucessfully download. So it's the FW code that fails... and note that the Zend validation code above does work correctly; I get errors if invalid entries are made.
Also, I note that my hosting providers only support PHP 5.2.14, whereas on my XAMPP installation I'm using 5.3 Could that be an issue?
Copy link to clipboard
Copied
Ran one last test - I literally posted the files upload_test_multi.php and process_upload.php from your demo code, only changing the paths to the upload directory and the Zend FW library. I had to comment out the mimetype validation because I got errors such as:
- The mimetype of file 'sosp-figure1-small.png' could not be detected
With validation off, the upload would proceed and give me a success result such as:
- sosp-figure1-small.png uploaded successfully
But still nothing get uploaded. I'm stumped...
Copy link to clipboard
Copied
antares5 wrote:
Also, I note that my hosting providers only support PHP 5.2.14, whereas on my XAMPP installation I'm using 5.3 Could that be an issue?
No. Zend Framework 1.x works with PHP 5.2.
Try the following:
$destination = 'C:/upload_test'; // set to correct location
$uploader = new Zend_File_Transfer_Adapter_Http();
$uploader->setDestination($destination);if (!$uploader->receive()) {
$messages = $uploader->getMessages();
print_r($messages);
}
Copy link to clipboard
Copied
Ugh, I'm profoundly embarrassed - I had created two upload directories - one off my site root and one off a subfolder, and was looking in the wrong place for the uploaded files. Duh... now that I'm looking in the right place, sure enough there they are.
Sorry for wasting your time, and thanks for your help.
Great book BTW. Everything works as long as the coder pays attention to what they're doing... 😞
Copy link to clipboard
Copied
No problems. It's a mistake we've all made at one time or another. Glad you find the book useful.
Copy link to clipboard
Copied
The problem is when we keep making them ;-).
And I think the book is GREAT! Really shows how to put it all together.
Copy link to clipboard
Copied
David, It looks that its been a couple of years since someone posted to this site. I'm using your new book DW CS5 and I'm trying to implement the Zend_File_Transfer_Adapter_Http() for an upload page on a site that I'm creating. When I try to view my upload.php page I'm getting the following error.
Fatal error: Uncaught exception 'Zend_File_Transfer_Exception' with message 'The given destination is not a directory or does not exist' in C:\xampp\htdocs\php_Library\library\Zend\File\Transfer\Adapter\Abstract.php:1035 Stack trace: #0 C:\xampp\htdocs\rawflow\process_upload.php(12): Zend_File_Transfer_Adapter_Abstract->setDestination(NULL) #1 C:\xampp\htdocs\rawflow\upload.html(6): require_once('C:\xampp\htdocs...') #2 {main} thrown in C:\xampp\htdocs\php_Library\library\Zend\File\Transfer\Adapter\Abstract.php on line 1035.
I can navigate to the file through windows explorer, so I'm not sure why I'm getting a does not exist error.
Any thoughts on what I possibly missed when setting up my instance?
I'm really enjoying the book and have found it to be a great resource as I build my first dynamic site from the ground up.
Thanks,
J
Copy link to clipboard
Copied
I fixed this error, it was pretty simple once I figured it out. My process_upload.php was not in the correct folder.
Copy link to clipboard
Copied
Hello, mister David!
I can't solve a problem in the same book. I try to build a travel website like in your book. In lesson 10, we learn to upload images. My images are uploaded, but on the root of the site like that: /home/content/56/10647856/html/image_uploadjoshuatree2.jpg uploaded successfully
I set $destination = '/home/content/56/10647856/html/image_upload/';
in db_definitrions.php and in Abstract.php in zend lib in line 947
the site is hosted by godaddy. I know is not the best place to host, I encounter a lot of errors during the learnig process, but I think is good to leran from errors
I like your books!
Thanks!
Liviu Stanescu
Romania
Copy link to clipboard
Copied
I'm sorry, right in the moment when I click "post" I undersand where is MY ERROR, I modified Abstract file because of another error with a missing directory for upload, but I did not fix that error when I change the path, I fix it on godaddy setup on file extension! Sorry .
That the NLP's writers start with "take a peace of paper and write down your problem" or a keyboard!
Sorry!
Copy link to clipboard
Copied
opps... now I have uploaded img in corect dir, with corect name, probaly changing the code in a wrog place, again inevitably direct me to another error, I can't see imgs in edit, list, delete, places and photos
Copy link to clipboard
Copied
my stuppid again! I forget of course to say my site is not in the root, is a subdomain
the fix was: /image_upload/ instead image_upload/ in img src= code in all files.

