Codeginiter : chmod(): Invalid argument error

1.6k views Asked by At

I am using pdftk library for modify the pdf files. but i am getting the chmod(): Invalid argument error.

Following is my code :

  include('fillpdf/createXFDF.php');
    $fdf_file = 'fillpdf/acord.fdf';
    $acord = array();
    $acord['******'] = 'a';
    $acord['******'] = 'a';
    $pdf_file_url  = 'http://localhost/******/fillpdf/Cancellation.pdf';
    $fdf = createXFDF( $pdf_file_url, $acord );
    // print_r($fdf); die;
           if ($fp = fopen($fdf_file, 'w')) { 
                chmod($fdf, 777);
                fwrite($fp, $fdf, strlen($fdf));
                $CREATED = TRUE;
            } else {
                echo 'Unable to create file: ' . $fdf_file . '<br><br>';
                $CREATED = FALSE;
            } 
            // var_dump($CREATED); die;
    fclose($fp);
    $command = '"C:\\Program Files (x86)\\PDFtk\\bin\\pdftk.exe" C:\\xampp\\htdocs\\*******\\fillpdf\\Cancellation.pdf fill_form acord.fdf output C:\\xampp\\htdocs\\*******\\fillpdf\\Cancellation_new.pdf';
    exec($command);

I have given all the necessary permission to folder and files. but don't know what is wrong??

Thanks in advance!!!

2

There are 2 answers

1
prakash tank On BEST ANSWER

Why you need to give chmod($fdf,0777); to $fdf. It's not even the file. as per your code the $fdf = createXFDF( $pdf_file_url, $acord ); is calling function and it's not file. so just comment the chmod($fdf,0777); line and check your code is working or not??

Hope it helps!!!

5
Hikmat Sijapati On

Try like this...For chmod() function first number is always zero.

chmod(file,mode);

The mode parameter consists of four numbers:

1.The first number is always zero

2.The second number specifies permissions for the owner

3.The third number specifies permissions for the owner's user group

4.The fourth number specifies permissions for everybody else

include('fillpdf/createXFDF.php');
    $fdf_file = 'fillpdf/acord.fdf';
    $acord = array();
    $acord['******'] = 'a';
    $acord['******'] = 'a';
    $pdf_file_url  = 'http://localhost/******/fillpdf/Cancellation.pdf';
    $fdf = createXFDF( $pdf_file_url, $acord );
    // print_r($fdf); die;
           if ($fp = fopen($fdf_file, 'w')) { 
                chmod($fdf,0777);
                fwrite($fp, $fdf, strlen($fdf));
                $CREATED = TRUE;
            } else {
                echo 'Unable to create file: ' . $fdf_file . '<br><br>';
                $CREATED = FALSE;
            } 
            // var_dump($CREATED); die;
    fclose($fp);
    $command = '"C:\\Program Files (x86)\\PDFtk\\bin\\pdftk.exe" C:\\xampp\\htdocs\\*******\\fillpdf\\Cancellation.pdf fill_form acord.fdf output C:\\xampp\\htdocs\\*******\\fillpdf\\Cancellation_new.pdf';
    exec($command);