Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > BOOK: PHP and MySQL: Create-Modify-Reuse ISBN: 978-0-470-19242-9
BOOK: PHP and MySQL: Create-Modify-Reuse ISBN: 978-0-470-19242-9
This is the forum to discuss the Wrox book PHP and MySQL: Create-Modify-Reuse by Timothy Boronczyk, Martin E. Psinas; ISBN: 9780470192429
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: PHP and MySQL: Create-Modify-Reuse ISBN: 978-0-470-19242-9 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old October 18th, 2009, 03:14 PM
Authorized User
Join Date: Jul 2009
Posts: 77
Thanks: 4
Thanked 6 Times in 6 Posts
Default Chap 2 - Avatars and uploading files, (would apply to Chap 6 too)

PROBLEM 1. chapter 2 mistake in the file view.php

In the book at about line 100 there is a mistake.
      if (file_exists('avatar/' . $row['USERNAME'] . 'jpg')
This is missing the period before jpg
This is also missing a right parenthesis.

The correct way should be
     if (file_exists('avatar/' . $row['USERNAME'] . '.jpg'))
In the download code the mistake has been corrected.

PROBLEM 2. chapter 2 - upload_avatar.php

I had a problem with $_FILES['avatar']['error'] returning
error number 6 (UPLOAD_ERR_NO_TMP_DIR).
I solved it as follows.

If $_FILES['avatar']['error'] is error number 6,
then you need to go to your php.ini file and set up upload_tmp_dir.
For example, set it to
upload_tmp_dir = /usr/home/myname/www/htdocs/public_files

Also make sure the php.ini file has set
file_uploads = On

When you click the upload button, it will put the file
in that directory.
It gives the file some weird name like phpjpdKfT .
(its a different name every time you click upload)
When the script ends, the file is deleted.

The user's script should copy the file somewhere, and
the JpegThumbnail generator function does just
that. It copies the file to the avatars directory.

The quick deleting of the file makes it a little bit
mysterious because the script runs so fast you can
never see the file in the directory. Just to see it,
and for debugging, I temporarily put a sleep in
there and then I could actually see the file.

The book talks about uploading files in Chapter 2, page 57.
He talks about the uploaded file being temporarily stored and
deleted once the script ends. It was well written and there
is a lot of good information there,
but they did not go into the php.ini part. Since I ran into
this problem, I thought I would post it here.

In chapter 6, the section "Uploading Files", page 161,
the book also has code which checks $_FILES['file']['error']
so the above discussion about the php.ini file would apply
there too.

After I got around these 2 issues I was able to upload
the avatar.

Similar Threads
Thread Thread Starter Forum Replies Last Post
chap 6, sandeepgreaternoida BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 2 October 31st, 2013 09:05 AM
Chap. 9 - ValidationSummary Ciupaz BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 6 May 28th, 2008 09:58 PM
Chap 1: page33 ed123 BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 1 January 4th, 2008 01:14 PM
Chap 1 Where are the SQL table files? Jim Dean BOOK: Beginning Visual Basic 2005 Databases ISBN: 978-0-7645-8894-5 7 July 8th, 2006 01:29 PM
chap 15 manal_sag BOOK: Beginning ASP 3.0 2 July 10th, 2005 03:29 AM

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