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.

4
  • 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. Commented Apr 1, 2014 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 Commented Apr 1, 2014 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 Commented Apr 1, 2014 at 15:35
  • I got it working. There were mistakes with my file path. Commented Apr 2, 2014 at 11:18

1 Answer 1

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").

Sign up to request clarification or add additional context in comments.

3 Comments

i tried with 777 permission both for file and folder
Try passthru("convert 'sample_(2).pdf[1]' 'sample.jpg'"); and look what error it shows. Because exec doesnt display the result without additional parameters.
passthru("convert 'sample_(2).pdf[1]' 'sample.jpg' 2>&1"); is the right way. Because passthru only display STDOUT.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.