Jump to content

Recommended Posts

Hi guys been looking at this forum and it looks like it could be what i need, im new to php and have just taken on a website with some pages using it!

 

I think it was installed on a PHP 4 server as when we have just moved the site to a php5 server the code stopped working

 

I looked throught the pages and the code started with <?  as soon as i changed it to <?php it all started looking better, is this normal?

 

Next i have this page

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">

 

 

<?php  session_register("GlimpseDir");

  if(!$GlimpseDir) $GlimpseDir="/";

 

  $basedir="images/pics/";

 

  function reloadnow() {

    global $PHP_SELF;

    global $addons;

    header("Status: 302 Moved");

    header("Location: $PHP_SELF".$addons);

    exit(); }

 

  if($cancel) $action="";

  if($action=="root") $GlimpseDir="/";

  if($action=="chdr") $GlimpseDir=$file."/";

  if($action=="dele" && $confirm==1) { unlink($basedir.$file); $action="";}

  if($action=="move" && $confirm && $newfile) {

    rename($basedir.$file,$basedir.$newfile); $action=""; }

  if($action=="rmdr") rmdir($basedir.$file);

  if($action=="edit" && $confirm && $file) {

    $fp=fopen($basedir.$file,"w");

    fputs($fp,stripslashes($code));

    fclose($fp);

    $addons="?action=edit&file=".rawurlencode($file);

    reloadnow(); }

  if($upload) { copy($userfile,$basedir.$GlimpseDir.$userfile_name);

    reloadnow(); }

  if($touch) { touch($basedir.$GlimpseDir.$touchfile); reloadnow(); }

  if($mkdir) { mkdir($basedir.$GlimpseDir.$mkdirfile,0700); reloadnow();  }

?>

<HTML>

<HEAD>

<TITLE>Image Upload to "<?php echo $GlimpseDir;?>"</TITLE>

<link rel="stylesheet" type="text/css"

href="./css/stylesheet.css" />

</HEAD>

<BODY>

<table width="80%" border="0" align="center" valign="top" bgcolor=#FFFFCC>

  <tr align="left" bgcolor="#009900">

    <th><a class="header" href="./BackOfficeHomepage.asp">Articles Manager</a></th>

    <th><a class="header" href="./BackOfficeAdverts.asp">Adverts Manager</a></th>

    <th><a class="header" href="./BackOfficeSections.asp">Sections Manager</a></th>

<th><a class="header" href="./FrontPage.asp" target="_blank">View Website</a></th>

    <th><a class="header" href="./BackOfficeLogin.asp">Log Out</a></th>

  </tr>

 

<?php

 

if ($action=="dele") {

    echo "<tr><td colspan=5>Are you sure you want to delete $file ?<BR>";

    echo "<A HREF=\"$PHP_SELF?action=dele&file=" . rawurlencode($file) . "&confirm=1\">YES</A><BR>";

    echo "<A HREF=\"$PHP_SELF\">NO</A><BR>";

    echo "</td></tr></table></BODY></HTML>";

    exit(); }

?>

<tr><td colspan=5> </td></tr>

<tr><td colspan=5><font color="#008000" size="3"><b>Upload to the <font color="#FF0000">Article</font> Image Folder</b></font></td></tr>

<tr><td colspan=5>Please ensure that the images uploaded are in .jpg or .gif format only and are of a suitable size</td></tr>

<tr><td colspan=5> </td></tr>

<tr><td colspan=5>

<TABLE BORDER="1" align="center" bordercolor="#008000" width="80%">

<TR align="left"><Th width="50%">Filename</TD><Th width="10%">Type</TD><Th width="10%">Size</TD><Th width="30%" colspan="2">Action</TD></TR>

<?php $handle=opendir($basedir . $GlimpseDir);

  while($file = readdir($handle)) {

    if ($file != "." && $file != "..") {

        $filename=$basedir.$GlimpseDir.$file;

        $fileurl=rawurlencode($GlimpseDir.$file);

        echo "<TR>";

        echo "<TD>" . htmlspecialchars($file) . "</TD>\n";

        echo "<TD>" . filetype($filename) . "</TD>\n";

        echo "<TD>" . filesize($filename) . "</TD>\n";

        //echo "<TD>";

        if(filetype($filename)=="file") {

echo "<TD><A HREF=\"$basedir$file\" target='_blank'>View File</A></TD>";

        echo "<TD><A HREF=\"$PHP_SELF?action=dele&file=$fileurl\">Del File</A></TD>";

        } if(filetype($filename)=="dir") {

        echo "<TD><font color='#000080'><A HREF=\"$PHP_SELF?action=chdr&file=$fileurl\">Change Dir</A></font></TD>";

        echo "<TD><font color='#000080'><A HREF=\"$PHP_SELF?action=rmdr&file=$fileurl\">Remove Dir</A></font></TD>";

        }

        //echo "</TD>";

        echo "</TR>\n";

        }

    }

  closedir($handle);

?>

</TABLE>

</td></tr>

<BR>

<tr><td colspan="5" align="center">

 

 

 

<FORM ENCTYPE="multipart/form-data" METHOD="POST" ACTION="<?php echo $PHP_SELF;?>">

<INPUT NAME="userfile" TYPE="file">

    <INPUT TYPE="SUBMIT" NAME="upload" VALUE="Upload File"><BR>

<INPUT TYPE="TEXT" NAME="mkdirfile">

    <INPUT TYPE="SUBMIT" NAME="mkdir"  VALUE="Make New Directory"><BR>

</FORM>

 

 

</td></tr>

</table>

</BODY>

</HTML>

 

 

I have had to make a few more changes to get it to work but it still does not and wondered is there anything obvious anyone can see which would stop it?

 

The problem im having with it is it does not actually do anything it should apart fromlist the directory, it wont upload or create and new folder..

 

If you go to the URL http://www.mauritiusnews.co.uk/UploadPicsImg.php

 

you can see it working, i have noticed if you click a command like DEL picture this then becomes the SELF.

 

Very strange stuff.

 

Thanks

 

Link to comment
https://forums.phpfreaks.com/topic/55701-very-new-to-php-and-stuck/
Share on other sites

I looked throught the pages and the code started with <?  as soon as i changed it to <?php it all started looking better, is this normal?

 

Yeah, that is normal. There is a setting in php to allow the short open tags (<?) - in php5 this is disabled by default.

 

Looks to me like the rest of the problems are caused by a setting called register_globals. Again, in php5, this is turned off by default. If you add in the following at the top of your file:

 

<?php  
session_register("GlimpseDir"); 
//this is the bit to add
$action = $_GET['action'];
$userfile = $_POST['userfile'];
$upload = $_POST['upload'];
$mkdirfile = $_POST['mkdirfile'];
$mkdir = $_POST['mkdir'];
//end of stuff to add
?>

 

What register_globals does, is automatically create variables for all of those in the post/get/session data etc. So, if your url was: http://www.example.com/index.php?foo=bar

Then with register_globals on, you could access the value of foo (which in this case is bar) with the variable $foo. With it off, you use $_GET['foo']

Thats absolutly brilliant guys thanks so much for your help this has solved the problem straght away!

 

is register_globals a bad thing i was told this should be set to off in most cases.

 

When writing PHP code in the suture is there a rule to stick by to no need this switched on?

 

Thanks Again!

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.