LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to run linux commands in php (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-run-linux-commands-in-php-771136/)

ramakrishnankt 11-23-2009 11:30 PM

How to run linux commands in php
 
Hi,
I installed popper utils to convert pdt into html in my ubuntu.
In terminal the command pdftohtml -c Desktop/resume.pdf
works well
but in php
<?php
echo exec('pdftohtml -c Desktop/resume.pdf');
?>
not works why?

Thanks
Ramakrishnan

firewiz87 11-23-2009 11:58 PM

If you are using a shared hosting server... chances are that you do not have command line access...

If you are trying to run it locally on your computer check the path.... the command may not be executed in your home directory....

Posting the output (if any) would help

linuxlover.chaitanya 11-24-2009 12:07 AM

Most probably the path to the file is culprit. While running in a script try to use complete paths.
Use /home/user/Desktop/file.pdf and see if it works.

AngTheo789 11-24-2009 12:56 AM

I agree with the previous poster that that full pathnames have to be used, but only if the PHP script is initiated via a web browser. If the script is launched from the commandline, then it can use realtive paths as well. In the current case the script will run from your shell only if your working directory is your home directory (assuming that "Desktop" is located there).

ramakrishnankt 11-24-2009 01:07 AM

how to run linux command in php
 
Quote:

Originally Posted by AngTheo789 (Post 3767609)
I agree with the previous poster that that full pathnames have to be used, but only if the PHP script is initiated via a web browser. If the script is launched from the commandline, then it can use realtive paths as well. In the current case the script will run from your shell only if your working directory is your home directory (assuming that "Desktop" is located there).

Thanks

Now i changed that as into
exec("/usr/bin/pdftohtml -c /var/www/pdf/resume.pdf /var/www/pdf/resumehtml.html");

still it not works...

ramakrishnankt 11-24-2009 01:08 AM

how to run linux command in php
 
Quote:

Originally Posted by linuxlover.chaitanya (Post 3767566)
Most probably the path to the file is culprit. While running in a script try to use complete paths.
Use /home/user/Desktop/file.pdf and see if it works.

Thanks
i changed it as
exec("/usr/bin/pdftohtml -c /var/www/pdf/resume.pdf /var/www/pdf/resumehtml.html");
still it not works
but this is works well in terminal

linuxlover.chaitanya 11-24-2009 01:13 AM

Ok, just minute, you are putting the commands in quotes while the command should be between the back ticks ``. Change it.

ramakrishnankt 11-24-2009 01:25 AM

how to run linux command in php
 
Thanks to all for your support,
I corrected that problem since my destination folder has no rights for write.
i refered it from http://stackoverflow.com/questions/5...ed-via-browser
now output(html files are written to my destination)

backticks also works well..
Thanks for full path,backticks information
But still one problem

output files come with readonly why?
i tried to use
chmod -R 777 /home/node2/Desktop
chmod: changing permissions of `/home/node2/Desktop/resume001.png': Operation not permitted
chmod: changing permissions of `/home/node2/Desktop/resume_ind.html': Operation not permitted
chmod: changing permissions of `/home/node2/Desktop/resume-1.html': Operation not permitted
chmod: changing permissions of `/home/node2/Desktop/resume.html': Operation not permitted
this is i get why?

these files has owner as www-data
how to change readonly
Thanks
Ramakrishnan

paulsm4 11-24-2009 10:54 PM

BTW - this whole little adventure could be a *HUGE* security risk.

ALWAYS be careful about what you let run on the server. VERY careful!

IMHO .. PSM

ramakrishnankt 11-24-2009 11:16 PM

So it is not possible


All times are GMT -5. The time now is 02:47 AM.