Jump to content

php code works on site A but not site B -- both PHP sites


inosent

Recommended Posts

i have this code:

 

http://inovasphere.com/form/results.zip

 

what it does is turns html form contents into an fdf file

 

it works here:

 

http://inovasphere.com/form

 

but not here

 

http://americanlawfirm.net/form

 

i think the issue is the directory structure

 

when i use my filezilla to upload to inovasphere the root directory is just:

 

"/ "

 

whereas in the root directory window with the americanlawfirm site i see:

 

"/www "

 

so it is like the code cant find the folder to put the result file in. not sure

 

Did it occur to you to post the code in question?

 

Also, it could be apache/linux/php etc version differences, e.g. using PHP 5 code on a PHP 5 server will work, but not on a PHP 4 server. Although PHP is generally backwards compatible.

 

Anyways, try to post the code

there r 3 files

 

createFDF.php

index.php

pdf_process.php

 

<?php

function createFDF($file,$info){
    $data="%FDF-1.2\n%âãÏÓ\n1 0 obj\n<< \n/FDF << /Fields [ ";
    foreach($info as $field => $val){
    	if(is_array($val)){
        	$data.='<</T('.$field.')/V[';
        	foreach($val as $opt)
        		$data.='('.trim($opt).')';
        	$data.=']>>';
    	}else{
        	$data.='<</T('.$field.')/V('.trim($val).')>>';
    	}
    }
    $data.="] \n/F (".$file.") /ID [ <".md5(time()).">\n] >>".
        " \n>> \nendobj\ntrailer\n".
        "<<\n/Root 1 0 R \n\n>>\n%%EOF\n";
    return $data;
}
?>

 

===========

 

<?php

    include dirname(__FILE__).'/pdf_process.php';
    echo '<?xml version="1.0" encoding="iso-8859-1"?>',"\n";    // because short_open_tags = On causes a parse error.
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <title></title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta name="description" content="A PHP solution to filling a PDF file's form fields with data from a submitted HTML form." />

</head>


<body>
  <div id="container">
<?php
    if(isset($CREATED)){
?>
<a href="<?php echo str_replace(dirname(__FILE__).'/','',$fdf_file) ?>">download</a> 
<?php
    }
?>
  
   <div>
   </div>

   <div>
   
    <form method="post" action="<?php echo $_SERVER['REQUEST_URI'] ?>">
     <table cellpadding="3" cellspacing="0" border="0">
      <tr><td>Name</td><td><input type="text" name="__NAME__" value="<?php if(isset($_POST['__NAME__'])) echo $_POST['__NAME__']; ?>" /></td></tr>
      <tr><td>Title</td><td><input type="text" name="__TITLE__" value="<?php if(isset($_POST['__TITLE__'])) echo $_POST['__TITLE__']; ?>" /></td></tr>
      <tr><td>Email</td><td><input type="text" name="__EMAIL__" value="<?php if(isset($_POST['__EMAIL__'])) echo $_POST['__EMAIL__']; ?>" /></td></tr>
      <tr><td>Address</td><td><input type="text" name="__ADDRESS__" value="<?php if(isset($_POST['__ADDRESS__'])) echo $_POST['__ADDRESS__']; ?>" /></td></tr>
      <tr><td>City</td><td><input type="text" name="__CITY__" value="<?php if(isset($_POST['__CITY__'])) echo $_POST['__CITY__']; ?>" /></td></tr>
      <tr><td>State</td><td><input type="text" name="__STATE__" value="<?php if(isset($_POST['__STATE__'])) echo $_POST['__STATE__']; ?>" /></td></tr>
      <tr><td>Zip</td><td><input type="text" name="__ZIP__" value="<?php if(isset($_POST['__ZIP__'])) echo $_POST['__ZIP__']; ?>" /></td></tr>
      <tr><td>Phone</td><td><input type="text" name="__PHONE__" value="<?php if(isset($_POST['__PHONE__'])) echo $_POST['__PHONE__']; ?>" /></td></tr>
      <tr><td>Fax</td><td><input type="text" name="__FAX__" value="<?php if(isset($_POST['__FAX__'])) echo $_POST['__FAX__']; ?>" /></td></tr>
     </table>
     <input type="submit" />
    </form>
   </div>

   <div>
   
   </div>

   <div>
   </div>

   <div>

</body>
</html>

 

 

-----------------------

 

<?php

    require_once 'createFDF.php';
    $pdf_file='http://inovasphere.com/form/test.pdf';

    // allow for up to 25 different files to be created, based on the minute
    $min=date('i') % 25;
    
    $fdf_file=dirname(__FILE__).'/results/posted-'.$min.'.fdf';

    if(isset($_POST['__NAME__'])){
        $_POST['__CSZ__']=$_POST['__CITY__'].', '.
                          $_POST['__STATE__'].' '.
                          $_POST['__ZIP__'];

        // get the FDF file contents
        $fdf=createFDF($pdf_file,$_POST);

        // Create a file for later use
        if($fp=fopen($fdf_file,'w')){
            fwrite($fp,$fdf,strlen($fdf));
            $CREATED=TRUE;
        }else{
            echo 'Unable to create file: '.$fdf_file.'<br><br>';
            $CREATED=FALSE;
        }
        fclose($fp);
    }
?>

well, it works on the first site

 

which of course i have already noted

 

ok, now that we are back to where we started, does anybody here have any ideas? or is this one of those sites where ppl say they dont know the answer 100 different ways?

 

i think the only issue is the code has to be tweaked to account for the different file structure of the latter server.

 

that is the most likely reason it *works* for the former and not the latter because the way the server folder layout is with the latter. i think that is pretty obvious. i just dont know how to adjust the code to account for the difference

 

i dont mind it if nobody has the answer, but what is the point of saying "it should not work on either server" when it already does on one, and not give any hint of how to address the issue?

 

somebody said i did not post the code, but i did, i posted the link to the zip file with all the files needed, so maybe somebody could upload them to their site and see what is what, etc

 

i also posted the links to the two sites with the one showing that is works and the other generating this error:

 

"Unable to create file: /home/lawfirm/public_html/form/results/posted-17.fdf"

 

for example, why does it say 'lawfirm' when the site is 'americanlawfirm.net'?

 

how can i get the true server path? and how do i change the code to accept the true server path for the folder/file locations instead of the http path?

 

this is the distinction i am not clear on

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.