[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

What does this PHP code do?

Posted on 2011-02-27
4
Medium Priority
?
655 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 6

Accepted Solution

by:
MatthewP earned 2000 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

656 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