Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
| Search | Today's Posts | Mark Forums Read
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP 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 February 13th, 2004, 01:18 PM
Registered User
 
Join Date: Feb 2004
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Beginning php 4 chapter 10 problems

I am trying to run the webeditor.php page, but i keep getting the pop up box saying "you can't edit me!"

the webeditor.php page is located in web/workshare/dir

code for webeditor.php

<?php
include "common.inc";
include "editor.inc";
include "navigator.inc";
$default_dir = "./docs";

function frame_page() {
   global $PHP_SELF, $dir;

?>
<HTML>
<HEAD><TITLE>Welcome to Web Text Editor!</TITLE></HEAD>
<FRAMESET COLS="200,*">
  <FRAME NAME="menu"
   SRC="<?php echo "$PHP_SELF?action=dir_page&dir=$dir"; ?>">
  <FRAME NAME="main"
   SRC="<?php echo "$PHP_SELF?action=editor_page&dir=$dir"; ?>">
  <NOFRAMES>
  <BODY TOPMARGIN="0" LEFTMARGIN="0">
  <P>This page uses frames, but your browser doesn't support them.</P>
  </BODY>
  </NOFRAMES>
</FRAMESET>
</HTML>
<?php
}

function upload_file_form() {
   global $PHP_SELF, $dir;
?>
<FORM METHOD="POST" ENCTYPE="MULTIPART/FORM-DATA"
      ACTION="<?php echo $PHP_SELF ?>" TARGET="menu">
<INPUT TYPE="HIDDEN" NAME="action" VALUE="upload_file">
<INPUT TYPE="HIDDEN" NAME="dir" VALUE="<? echo $dir ?>">
   Local Filename <INPUT TYPE="FILE" NAME="userfile">
   Uploaded Filename<INPUT TYPE="TEXT" NAME="filename" LENGTH="20">
   <INPUT TYPE="SUBMIT" NAME="submit" VALUE="upload">
</FORM>
<?php
}

function upload_file() {
   global $userfile, $userfile_name, $userfile_size, $userfile_type,
          $filename, $default_dir, $dir, $PHP_SELF, $WINDIR;

   $def_length=strlen($default_dir);
   if(!empty($dir)) $dir_test=substr($dir, 0, $def_length);

   if(empty($dir) || ($dir_test!=$default_dir)) {
      error_message("$dir/$filename is illegal directory.");
   }

   if(!isset($WINDIR)) $userfile = str_replace("\\\\","\\", $userfile);
   if(empty($filename)) $filename = basename($userfile_name);

   if($userfile_size <= 0) {
      error_message("$filename is empty.");
   }
   if(file_exists("$dir/$filename")) {
      error_message("$filename already exists.");
   }
   if(!@copy($userfile, "$dir/$filename")) {
      error_message("Can't copy $userfile_name to $filename.");
   }
   if(!isset($WINDIR) && !@unlink($userfile)) {
      error_message("Can't delete $userfile_name.");

   }
   html_header();
   $file_info_array = file_info("$dir/$filename");
   if($file_info_array["filetype"] == 'text')
      echo "<SCRIPT>parent.main.location.href='$PHP_SELF?acti on=editor_page&dir=$dir&filename=$filename';
         </SCRIPT>";
   dir_page();
   html_footer();
}

$def_length=strlen($default_dir);
if(!empty($dir)) $dir_test=substr($dir, 0, $def_length);

if(empty($dir) || ($dir_test!=$default_dir)) {
   $dir = $default_dir;
}

if($filename == basename($PHP_SELF)) error_message("You can't edit me!");

switch ($action) {
   case "editor_page":
      html_header();
      upload_file_form();
      editor_page();
      html_footer();
      break;
   case "dir_page":
      html_header();
      dir_page();
      html_footer();
      break;
   case "make_dir":
      make_dir();
      break;
   case "delete_dir":
      delete_dir();
      break;
   case "delete_file":
      delete_file();
      break;
   case "save_file":
      save_file();
      break;
   case "upload_file":
      upload_file();
      break;
   default:
      frame_page();
   break;
}
?>


 
Old February 13th, 2004, 02:29 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

What's register_globals set to in php.ini?

  http://p2p.wrox.com/archive/beginnin...2002-11/17.asp


Take care,

Nik
http://www.bigaction.org/
 
Old February 13th, 2004, 04:35 PM
Registered User
 
Join Date: Feb 2004
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

Its set to OFF, but i changed it to ON and nothing has changed.

Martin

 
Old February 13th, 2004, 06:21 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 is webeditor.php defined? I don't have the books, but it looks like it's using a deprecated interface to uploaded files.

Still, with register_globals = on, I would guess that it should work. You might want to check your server's file upload settings.


Still, your error message is displayed when the file you're trying to edit IS the running PHP script -- the script doesn't let you edit it.

I'd trace through the script a little more closely to determine where/when $filename is being set. Use debugging output to display the state of your variables. (i.e., echo the contents of relevant variables during your scripts execution to verify that they're set to what you expect.)


Take care,

Nik
http://www.bigaction.org/




Similar Threads
Thread Thread Starter Forum Replies Last Post
chapter 10 Emailing with php - firstmail.php vijdev BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 0 July 19th, 2007 01:12 AM
Beginning Visual C# Exercises - Chapter 10 seblake C# 1 July 29th, 2004 05:10 PM
Chapter 10 - Beginning VB6 database programming darryck VB Databases Basics 3 October 13th, 2003 03:40 AM
Beginning php 4 chapter 10 problems ade Beginning PHP 2 June 19th, 2003 02:43 PM





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