Solved

What does this PHP code do?

Posted on 2011-02-27
4
643 Views
Last Modified: 2012-05-11
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

0
Comment
Question by:Karessa
  • 3
4 Comments
 
LVL 6

Accepted Solution

by:
MatthewP earned 500 total points
ID: 34993724
Pretty much yes.

It creates a folder called CaptivateResults in the lowest directory it has access to, then folders named after the values of the variables CompanyName, DepartmentName, CourseName - each nested in the previous one, then a file named after the value for the Filename.variable and dumps the value of Filedata into it. Im not sure why it's using two slashes as separators though normally only one would be required. It would also be wise to test that the results of each action to ensure that the folders are created and the file is actually writeable, also that the file doesn't exist already and is overwritten when this may not be the desired effect.
0
 

Author Comment

by:Karessa
ID: 34994046
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!
0
 
LVL 6

Expert Comment

by:MatthewP
ID: 34997184
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.
0
 
LVL 6

Expert Comment

by:MatthewP
ID: 34997192
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.
0

Featured Post

Easy Project Management (No User Manual Required)

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now