Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5
This is the forum to discuss the Wrox book Beginning PHP4 by Wankyu Choi, Allan Kent, Chris Lea, Ganesh Prasad, Chris Ullman; ISBN: 9780764543647
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #11 (permalink)  
Old December 11th, 2003, 12:35 PM
Friend of Wrox
Points: 2,570, Level: 21
Points: 2,570, Level: 21 Points: 2,570, Level: 21 Points: 2,570, Level: 21
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: San Diego, CA, USA
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

So you're having a register_globals problem, then? What's your register_globals setting? If it's "off" (which, as of php 4.1.0 is the default), then you'll need to fix the code as follows:

All your post data should be accessed via $_POST['varname'] instead of $varname. This includes $action and $SUBMIT.

All your server variables should be accessed via $_SERVER['varname'] instead of $varname. This includes $PHP_SELF.


For more info, search the site for register_globals posts. There are thousands. =) Start here:

  http://p2p.wrox.com/archive/beginnin...2002-11/17.asp
  http://www.google.com/search?q=site:...ster%5Fglobals


Also, read the manual section on file uploads:
  http://www.php.net/features.file-upload


Take care,

Nik
http://www.bigaction.org/
Reply With Quote
  #12 (permalink)  
Old December 12th, 2003, 12:04 PM
Registered User
 
Join Date: Dec 2003
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The register_global is on. I have a working script for uploading files now. Thanks for your help.
I noted that even though the register_global is on, I still have to use $_POST['varname']. Don't really see why this would be the case?

Reply With Quote
  #13 (permalink)  
Old December 12th, 2003, 12:15 PM
Friend of Wrox
Points: 2,570, Level: 21
Points: 2,570, Level: 21 Points: 2,570, Level: 21 Points: 2,570, Level: 21
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: San Diego, CA, USA
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Where do you have to use $_POST['varname']? My guess is that you're trying to access your global variables from within a function.

In a function, there are two ways of accessing global variables. 1) You can import global variables into function scope with the "global" keyword, and 2) you can access them via the $GLOBALS array. $GLOBALS is a "superglobal", which means it's ALWAYS in scope. That's what makes it "super". You don't have to explicitly import them into function scope.

I recommend trying to use $_POST['varname'] to access your form variables, even if register_globals is on. That way, you get in the habit of doing so for when you start writing new scripts geared toward stricter settings (i.e. register_globals = off and error_reporting = E_ALL)

For more information about variables, their scope, and the global keyword, read:
  http://www.php.net/variables.scope



Take care,

Nik
http://www.bigaction.org/
Reply With Quote
  #14 (permalink)  
Old January 8th, 2009, 08:13 AM
Registered User
 
Join Date: Jan 2004
Location: , , .
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Please note that your servers may have upgraded their PHP version since this book was published in the year 2000. The current download source files donot all reflect these changes in PHP4 therefore chapter 10 the upload file looks to be affected. I will post an alternative code snippet here shortly.

Old Source code file_upload.php:
PHP Code:
<?
//file_upload.php
$archive_dir "./docs";
function 
upload_form() {
   global 
$PHP_SELF;
?>
<FORM METHOD="POST" ENCTYPE="MULTIPART/FORM-DATA" 
   ACTION="<? echo $PHP_SELF ?>">
   <INPUT TYPE="HIDDEN" NAME="action" VALUE="upload">
   Upload file!
   <INPUT TYPE="FILE" NAME="userfile">
   <INPUT TYPE="SUBMIT" NAME="SUBMIT" VALUE="upload">
</FORM>
<?
}

function 
upload_file() {
   global 
$userfile$userfile_name$userfile_size
         
$userfile_type$archive_dir$WINDIR;

   if(isset(
$WINDIR)) $userfile str_replace("\\\\","\\"$userfile);
   
   
$filename basename($userfile_name);
   
   if(
$userfile_size <= 0) die ("$filename is empty.");

   if(!@
copy($userfile"$archive_dir/$filename"))
      die(
"Can't copy $userfile_name to $filename.");
   
   if(!isset(
$WINDIR) && !@unlink($userfile))
      die (
"Can't delete the file $userfile_name.");

   echo 
"$filename has been successfully uploaded.<BR>";
   echo 
"Filesize: " number_format($userfile_size) . "<BR>";
   echo 
"Filetype: $userfile_type<BR>";
}
?>
<HTML>
<HEAD><TITLE>FILE UPLOAD</TITLE></HEAD>
<BODY>
<?
if($action == 'upload'upload_file();
else 
upload_form();
?>
</BODY>
</HTML>

New Code to follow:
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problems with uploading andregustavo_castro Classic ASP Professional 0 November 7th, 2008 09:02 AM
Problems uploading on dreamweaver CS3!!!! omgdesigns.com Dreamweaver (all versions) 2 May 29th, 2008 05:20 AM
asp file upload script having problems with MYSQL paulmcn Classic ASP Databases 0 September 16th, 2005 01:26 PM
asp uploading script zeeshandar Classic ASP Components 3 November 13th, 2004 07:48 PM



All times are GMT -4. The time now is 12:42 PM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.