PHP issues opening a file

Discussion in 'Mac Programming' started by slooksterPSV, Nov 26, 2005.

  1. macrumors 68030

    slooksterPSV

    Joined:
    Apr 17, 2004
    Location:
    Nowheresville
    #1
    Here's my code: I can create a new project, save and all that, but I cannot whatsoever open an existing project.
    Code:
    <?php
    //MADE BY SHAWN BARNES
    	if(!defined('USR'))
    		return;
    	
    	global $error; $error = 0;
    	
    	if(isset($_REQUEST['savefile']))
    	{
    		saveFile($_REQUEST['data'], $_REQUEST['prj']);
    	}
    	
    	if(isset($_REQUEST['newProj']))
    	{
    		createPropXML($_REQUEST['author'], $_REQUEST['title'], 
    			$_REQUEST['height'], $_REQUEST['width'], $_REQUEST['resize'], 
    			$_REQUEST['xpos'], $_REQUEST['ypos'], $_REQUEST['folderName']);
    		createBlankPHP($_REQUEST['folderName']);
    		openProjectFile($_REQUEST['folderName']);
    	}
    	elseif(isset($_REQUEST['prj']))
    	{
    		showEditor($_REQUEST['prj']);
    	}
    	elseif(isset($_REQUEST['openProj'])){
    		openProjectFiles($_REQUEST['openProj']);
    	}elseif($_REQUEST['menuopt'] == 1)
    	{
    		showNewProject();
    	}
    	elseif($_REQUEST['menuopt'] == -1)
    	{
    		showOpenProject();
    	}
    	else{
    		showMenu();
    	}
    	
    	function showEditor($arg1)
    	{
    	
    		if(isset($arg1)){
    			$hdl = fopen(HOMEDIR.USR."/".$arg1.".eyeapp/aplic.php", 'r');
    			$data = fread($hdl, filesize(HOMEDIR.USR."/".$arg1.".eyeapp/aplic.php"));
    			fclose($hdl);
    			echo $arg1;
    			echo "<form action='desktop.php?a=$eyeapp' method=post' name='appMake'>";
    			echo "<textarea rows='20' cols='63' name='data'>"; 
    			echo textarea(rtrim($data));
    			echo "</textarea>";
    			echo "<input type='hidden' name='prj' value='".$arg1."'><br><input type='hidden' name='savefile' value='always'><input type='submit'>";
    			echo "</form>";
    		}else{
    			//echo "ERROR: There is an error in how you are trying to open your project.";
    		}
    	}
    	
    	function showNewProject()
    	{
    		echo "<form action='desktop.php?a=$eyeapp' method='post' name='appMakeNew'>
    			  Name:       <input type='text' value='' name='author'><br>
    			  Title:      <input type='text' value='' name='title'><br>
    			  Height:     <input type='text' value='' name='height'><br>
    			  Width:      <input type='text' value='' name='width'><br>
    			  Resize (only no works):<input type='text' value='' name='resize'><br>
    			  X Position: <input type='text' value='' name='xpos'><br>
    			  Y Position: <input type='text' value='' name='ypos'><br>
    			  Folder Name:<input type='text' value='' name='folderName'><br>
    			  Create Project (type yes to create or leave blank):<input type='text' name='newProj'><br>
    			  <input type='hidden' name='prj'><input type='hidden' name='new'><br>
    			  <input type='submit' onClick='new.value=\'new\'; newProj.value=\'new\';'></form>";
    	}
    	
    	function openProjectFile($arg1)
    	{
    		global $error;
    		if($error == 0){
    			$x = 1;
    			if(!($hdl = fopen(HOMEDIR.USR."/".$arg1.".prj", 'r'))){
    			$hdl = fopen(HOMEDIR.USR."/".$arg1."", 'r');
    			}
    			while($x <= 8) {
    				$data = fgets($hdl);
    				$x += 1;
    			}
    			fclose($hdl);
    			if(dirname(HOMEDIR.USR."/".$data.".eyeapp"))
    			{
    				showEditor($data);
    			}
    		}
    		
    	}
    	
    	function createPropXML($arg1, $arg2, $arg3, $arg4, $arg5, $arg6, $arg7, $arg8)
    	{
    		$projectData = "".$arg1."\n".$arg2."\n".$arg3."\n".$arg4."\n".$arg5."\n".$arg6."\n".$arg7."\n".$arg8."";
    		$xmlData = '<?xml version="1.0"?>
    					<eyeOSapp>
      					<author>'.$arg1.'</author>
      					<title>'.$arg2.'</title>
      					<window height=\' '.$arg3.' \' width=\' '.$arg4.' \'>
        				<fullscreen>no</fullscreen>
         				<resize>'.$arg5.'</resize>
         				<x_pos>'.$arg6.'</x_pos>
         				<y_pos>'.$arg7.'</y_pos>
      					</window>
    					</eyeOSapp>';
    
    		if(dir(HOMEDIR.USR."/".$arg8.".eyeapp") || is_file(HOMEDIR.USR."/".$arg8.".prj")){
    			showError("ERROR DIRECTORY, FILES OR PROJECT ALREADY EXISTS OR HAS THE SAME NAME\nBE SURE TO CHECK YOUR FILES");
    			showNewProject();
    			global $error;
    			$error = 1;
    		}else{
    			$hdl = fopen(HOMEDIR.USR."/".$arg8.".prj",'w');
    			fwrite($hdl, $projectData);
    			fclose($hdl);
    			mkdir(HOMEDIR.USR."/".$arg8.".eyeapp", 0777);
    			$hdl = fopen(HOMEDIR.USR."/".$arg8.".eyeapp/propietats.xml", 'w');
    			fwrite($hdl, $xmlData);
    			fclose($hdl);
    		}
    	}
    	
    	function createBlankPHP($arg1)
    	{
    		global $error;
    		if($error == 0){
    			$pD = 
    "<?php
    	if(!defined('USR'))
    		return;
    
    //PUT CODE HERE
    
    ?>";
    			$hdl = fopen(HOMEDIR.USR."/".$arg1.".eyeapp/aplic.php", 'w');
    			fwrite($hdl, $pD);
    			fclose($hdl);
    		}
    	}
    	
    	function saveFile($arg1, $arg2)
    	{
    		$hdl = fopen(HOMEDIR.USR."/".$arg2.".eyeapp/aplic.php", 'w');
    		fwrite($hdl, $arg1);
    		fclose($hdl);
    	}
    	
    	function showError($arg)
    	{
    		echo $arg;
    	}
    	
    	function showMenu()
    	{
    		echo "<form action='desktop.php?a=$eyeapp' method='post' name='makeAppMenu'>
    			 Create New Project:<input type='radio' name='option' onclick='menuopt.value=\"1\";'><br>
    			 Open Existing Project:<input type='radio' name='option' onclick='menuopt.value=\"-1\";'><br>
    			 <input type='hidden' name='menuopt'><input type='submit'></form>";
    	}
    	
    	function showOpenProject()
    	{
    		$dir = HOMEDIR.USR;
    		$dh  = opendir($dir);
    		echo "<form action='desktop.php?a=$eyeapp' method='post' name='appMakeOpen'>";
    		echo "Only choose a project with a .prj ending:<select name='openProj' onchange=''>";
    		while (false !== ($filename = readdir($dh))) {
       			$files[] = $filename;
       			echo "<option value='$filename'>$filename";
    		}
    		echo "</select><input type='hidden' name='open'><input type='submit' onClick='open.value=\'open\''></form>";
    	}
    ?>
    
     
  2. macrumors 68030

    superbovine

    Joined:
    Nov 7, 2003
    #2
    Any error messages? Have you traced what line of code it takes a dump at?
     
  3. thread starter macrumors 68030

    slooksterPSV

    Joined:
    Apr 17, 2004
    Location:
    Nowheresville
    #3
    I'm running this in eyeOS, so I think I'm going to reconfigure the code so I can see what shows up if it'll show.
     
  4. thread starter macrumors 68030

    slooksterPSV

    Joined:
    Apr 17, 2004
    Location:
    Nowheresville
    #4
    On the isset where it says openProj - its making an undefined call to openProjectFiles when it should be openProjectFile - stupid dumb error I made when typing it. DANG IT :(
     

Share This Page