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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
inosent1
Forum Commoner
Posts: 97
Joined: Wed Jan 28, 2009 12:18 pm

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

Post by inosent1 »

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
facets
Forum Contributor
Posts: 273
Joined: Wed Apr 13, 2005 1:53 am
Location: Detroit

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

Post by facets »

there could be many differences between your hosts. diff the output of phpinfo() on both hosts. you're looking for php version differences and libraries that are missing etc. that will get you started but we'll need more information if you expect any assistance.
inosent1
Forum Commoner
Posts: 97
Joined: Wed Jan 28, 2009 12:18 pm

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

Post by inosent1 »

well, fwiw, the code is exactly the same, both are php hosts

the only difference is the way the sites are structured

when i log into FTP to one i get right to the root, the other i get 'under' the root by one folder and to get to the http folder that affects what users see online i have to click on either the 'public_html' golder or the 'www' folder

i am pretty sure this is where the trouble is, i just cant figure out how to set the code to adjust for this
User avatar
yacahuma
Forum Regular
Posts: 870
Joined: Sun Jul 01, 2007 7:11 am

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

Post by yacahuma »

you dont mention what exactly is the error.
inosent1
Forum Commoner
Posts: 97
Joined: Wed Jan 28, 2009 12:18 pm

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

Post by inosent1 »

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

i dont get this error with the inovasphere site

===============

there r 3 files

createFDF.php
index.php
pdf_process.php

Code: Select all

<?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;
}
?>
 
===========

Code: Select all

<?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>
 

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

Code: Select all

<?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);
    }
?>
 
facets
Forum Contributor
Posts: 273
Joined: Wed Apr 13, 2005 1:53 am
Location: Detroit

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

Post by facets »

are the permissions different on the 'results' directory on each host.
inosent1
Forum Commoner
Posts: 97
Joined: Wed Jan 28, 2009 12:18 pm

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

Post by inosent1 »

yes, they are identical
User avatar
yacahuma
Forum Regular
Posts: 870
Joined: Sun Jul 01, 2007 7:11 am

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

Post by yacahuma »

can you try just to write something with file_put_contents('/fullpath/test.txt', 'test') and make sure a file get created in the right directory
Post Reply