Link to home
Start Free TrialLog in
Avatar of Karessa
Karessa

asked on

What does this PHP code do?

Does this code create a series of nested folders using the variables and create a file to be inside the inner folder that has the filedata written to it?

Thanks




<?php # InternalServerReporting.php
# Copyright 2000-2008 Adobe Systems Incorporated. All rights reserved.
#
   print "<pre>\n";

#
   foreach ($_POST as $k => $v) 
   {
  	  if($k == "CompanyName")
	  {
	    $CompanyName = $v;
      }
      if($k == "DepartmentName")
	  {
	    $DepartmentName = $v;
      }
      if($k == "CourseName")
	  {
	    $CourseName = $v;
      }
      if($k == "Filename")
      {
      	$Filename = $v;
      }
      if($k == "Filedata")
      {
      	if(get_magic_quotes_gpc())
		$Filedata = stripslashes($v);
		else
		$Filedata = $v;
      }
   }

	$ResultFolder = "./"."CaptivateResults";
	mkdir($ResultFolder);
	$CompanyFolder = $ResultFolder."//".$CompanyName;
	mkdir($CompanyFolder);
	$DepartmentFolder = $CompanyFolder."//".$DepartmentName;
	mkdir($DepartmentFolder);
	$CourseFolder = $DepartmentFolder."//".$CourseName;
	mkdir($CourseFolder);
	$FilePath = $CourseFolder."//".$Filename;
	$Handle = fopen($FilePath, 'w');
	fwrite($Handle, $Filedata);
	fclose($Handle);


   print "</pre>\n";
?>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of MatthewP
MatthewP
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Karessa
Karessa

ASKER

Thanks, Matthew.

I can't get the file to work. Maybe the two slashes are the problem, so I'll take them out and see what happens. It would be strange because the file is just as it came from Adobe, but who knows.

Thanks again!
It is accepting variables in POST format - meaning a form needs to be submitted via the POST method.

Near the top under your print "<pre>"; line add

var_dump($_REQUEST);

which will dump out all the data that has been sent so you can see if it's getting through.

It is also expecting the root directory to have write permissions to create the folders and write the data. On linux you must make sure the directory is CHMOD 777 if that means anything to you. I wouldn't know on Windows Im afraid.

Also change things like:

mkdir($ResultFolder);

to:

mkdir($ResultFolder) or die("Cannot create folder $ResultFolder")

so you can see where problems are occurring. At a guess it is either no write permissions or the data isn't getting there.
sorry,

var_dump($_POST);

to display all the data that has been sent via POST. $_REQUEST shows all variables if they are sent by the GET method too, you only need to check for POST.