0

I am trying to run convert 'sample_(2).pdf[1]' 'sample.jpg' through php exec like below

> exec(" convert 'sample_(2).pdf[1]' 'sample.jpg' ");

But it is not working in php but works great in terminal. I tried below codes also to check wethee exec is working with php.

echo exec('whoami'); //It is working and giving me result

exec("cp 'sample_(2).pdf' sample2.pdf");

//It is not working.

But all the commands are running in terminal. Any idea would help me. I am scratching my head for the last two days.

EDIT

I got it working. There were mistakes with my file path.

jack
  • 473
  • 5
  • 21
  • fix your quoting on the cp sample where its not working, '' ' ' ' '' etc etc all horrible. Secondly exec may be disabled by the user running apache. – Dave Apr 01 '14 at 15:13
  • I am using those ""' etc to escape special character. It is all working fine from terminal. And the user is same in both putty and connecting credentials – jack Apr 01 '14 at 15:24
  • yeah........ no manage your special chars external to the exec command `exec("cp $source $destination");` after you've escaped properly using \ for command line. and running the script from the terminal runs it with the permissions of the user logged in, running it via web server runs it with your apache user (www-data on deb/httpd on RH) running it via ftp runs it as your ftp user. Ftp users are usually locked out from executing scripts anyway – Dave Apr 01 '14 at 15:35
  • I got it working. There were mistakes with my file path. – jack Apr 02 '14 at 11:18

1 Answers1

0

I guess that the web server does not have permission to write to the folder you want to write. Check the folder permissions for your webserver (probably "www-data").

Marbel
  • 1
  • 1
  • i tried with 777 permission both for file and folder – jack Apr 01 '14 at 15:25
  • Try passthru("convert 'sample_(2).pdf[1]' 'sample.jpg'"); and look what error it shows. Because exec doesnt display the result without additional parameters. – Marbel Apr 01 '14 at 15:32
  • passthru("convert 'sample_(2).pdf[1]' 'sample.jpg' 2>&1"); is the right way. Because passthru only display STDOUT. – Marbel Apr 01 '14 at 15:50