p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: PHP and MySQL: Create-Modify-Reuse ISBN: 978-0-470-19242-9 (http://p2p.wrox.com/forumdisplay.php?f=406)
-   -   Chapter 6, Ajax File Manager, error in upload.php file (http://p2p.wrox.com/showthread.php?t=78793)

kenj March 31st, 2010 09:06 PM

Chapter 6, Ajax File Manager, error in upload.php file
 
ISSUE # 1 - error in upload.php file

Chapter 6, upload.php file, the downloaded code,
lines 12 and 13 result in BASEDIR getting concatenated
to the file path twice. This is not correct.
Code:

$dir = realpath(BASEDIR . $_POST['dir']);
$target = BASEDIR . $dir . '/' . $_FILES['file']['name'];

You can correct it by removing the string BASEDIR from
line 13, like this.
Code:

$dir = realpath(BASEDIR . $_POST['dir']);
$target = $dir . '/' . $_FILES['file']['name'];

After making this fix, it worked for me.


Configuration note: I am using the downloaded code. The
downloaded code has a file named ajax.js which is the
correct filename.
In previous posts in this forum, there were some issues
because the book was referring to the file by
the name helper.js, but it should be ajax.js
Anyway, after I made the above change chapter 6
worked for me. I am in a UNIX/Linux environment.

Now, one more thing. you have to have your php.ini file set up
correctly in order for the uploads to work properly. I
discuss this in a previous post here:
http://p2p.wrox.com/book-php-mysql-c...hap-6-too.html

ISSUE #2 - duplicate file name from chapter 5

Chapter 6 has the following file name.
css/styles.css

The problem is chapter 5 has the exact same filename
in the same directory, In my view, the filenames should
be unique across chapters because they are in the same
directories.

chenken May 31st, 2010 11:48 AM

Thanks, kenj.

OS UNIX/Linux

<?php
define('BASEDIR', '/srv/apache/wrox/ch_06/files');
?>

but,OS Windows

<?php
define('BASEDIR', 'C:\anypath);
?>



<?php
define('BASEDIR', '..\files);
?>

don't work for me!!!

so. Advice for me , please.

kenj May 31st, 2010 01:44 PM

Hi Chenken

Did the file even upload successfully?
Check the value of $_FILES['file']['error']

If the file did not upload successfully, you
could start by checking the settings in the
php.ini file as outlined in post
Chap 2 - Avatars and uploading files, (would apply to Chap 6 too).

What kind of error messages are you getting?
Is there anything in the php error log file?
You might want to put some debugging statements
in upload.php and let us know where it is failing. Thanks.

chenken June 1st, 2010 12:37 PM

kenj ,Thank you !
 
Thanks, kenj.
upload successfully.
but
1. Under the New Folder, upload failed.( Saved under the Root )
2. Filename is chinese,upload after disorder code disorder.

kenj June 4th, 2010 08:46 PM

Hi chenken

You got the file uploaded, that's good.

Now all you have to do is get it copied to the
directory you want.

Check your lib/config.php file and make sure
your BASEDIR is set to what you want.

In upload.php put some print statements in there to
check the values of variables such as $dir and $target.

Try experimenting with the move_uploaded_file function
to make sure it can copy a file to the destination
you want.

Let us know what happens. Thanks.


All times are GMT -4. The time now is 06:44 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.