View Single Post
  #1 (permalink)  
Old October 18th, 2009, 03:14 PM
kenj kenj is offline
Authorized User
Points: 374, Level: 6
Points: 374, Level: 6 Points: 374, Level: 6 Points: 374, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2009
Location: San Jose, Californina
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.
Code:
      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
Code:
     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.
Reply With Quote