You must have installed FFMPEG in order to use this function - php

I'm using this script: GitHub Script Link
This script uses FFMPEG to convert MP4 to AVI and from AVI to MP3.
But I always getting the error:
You must have installed FFMPEG in order to use this function
But I have installed FFMPEG on my Linux Server.
This is the output of my CLI (puTTY):
As you can see I have it installed.
I'm sorry the script is to big to post it here but you can take a look.
Thanks for every help!

Run which ffmpeg from your PuTTY console, and see what you get. That's exactly what the script does to detect it:
private function has_ffmpeg() {
$sh = `which ffmpeg`;
return (bool) (strlen(trim($sh)) > 0);
}
It returns false if there's no output from the shell script (i.e. the length of the response is 0).
which only searches through folders defined in your $PATH. If you get no output when you run that command directly, then the script will get the same. This means the script considers that ffmpeg is not installed.
Therefore, as mentioned in the comments already, make sure your $PATH contains the folder in which the ffmpeg executables are stored. http://thegeekstuff.com/2012/07/linux-export-command-examples shows you how to check, and how to add things to it. You can find loads more examples online, for all the various distros.

Related

wkhtmltopdf not working in php script

I would like to use the wkhtmltopdf for HTML to PDF conversion.
When I have tried to convert it via linux terminal, it works fine.
But when I have tried with the php script it does not work.
I am trying execute the binary directly.
here is the code I am trying with PHP.
exec('/home/binary_loc/wkhtmltopdf http://www.google.com /home/user/output.pdf');
My binary is at the same folder where "index.php" exist.
I have tried to fetch the version of wkhtmltopdf binary with PHP, then it return the version.
But i don't able to understand why not it work to execute with php for pdf.
Here is code for version check using php.
error_reporting(E_ALL);
ini_set('display_errors', '1');
$cmd = "./wkhtmltopdf --version";
$t = shell_exec($cmd);
echo $t;
exit()
Do anyone has solution regarding it??
I want this because this will work in the shared hosting too. No need to install the wkhtmltopdf in the server.
Exec probably doesn't have permission to execute the file. PHP usually runs as either apache or nobody, rather than your user account. You'll have to make sure the execute bit is set for whatever user it runs under. You can use chmod 755 wkhtmltopdf from the directory it's under, to grant read and execute to all users.
Note that on some shared hosting, exec() is disabled. Check with your host to make sure you have access to it.
Define the complete path to the wkhtmltopdf executable and the complete path to the output folder.
To debug try something like this:
shell_exec("/home/binary_loc/wkhtmltopdf http://www.google.com /home/user/output.pdf > /home/user/debug.log 2>&1");
pipe the error in a file

PHP exec() with Pygments for PHP

I'm currently using the Pygments for PHP plugin that is located here: http://derek.simkowiak.net/pygments-for-php/.
The line that actually calls Pygments from that code is an exec() passed: pygmentize -f html $extra_opts -l $language $temp_name as the command. This all works fine, and I get back the output and it is formatted by the plugin.
What I would like to happen at the same time is for Pygments to create an image of it, so I pass exec() a similar command: pygmentize -f png $extra_opts -l $language -o $full_image_path/$output_file.png $temp_name This is where I run into a problem. The image never shows up in the expected folder.
However, if I var_dump() that command string before I exec() it and take it and run it straight from the command line, it works fine.
I have tried echoing exec('whoami') which tells me that the PHP user is www-data. I've tried giving permissions to www-data and changing ownership to www-data on the folder where I store the images. I've also tried changing permissions to 777 just to see what would happen, and the answer is nothing.
Is there something I'm missing? I'm running out of ideas to try. Thank you!
Edit: Another thing that I've checked is the output from the exec command, and the return value. It outputs an empty array, and it returns 1 as the return value.
Edit 2: After seeing that that directory should be writeable/readable for the PHP user, is it possible that pygments doesn't have permission to write it as a specific user? I'm not sure this makes sense, as when I run it myself it works fine, and in fact, when PHP runs it with the HTML lexer, it is able to run. I'm not very experienced in Python, so I don't know if this is a potential issue.
I guess you cannot do it like this.
$output_file.png
Try
$file = $output_file.".png"
and substitute in the exec
Ended up being an issue with the font that was installed for use by the www-root user. Apparently the one that is used by default for Pygments was installed only for the user that I was running as when I use the command line.
The way I was able to figure this out, was running
exec("$command 2>&1", $out, $code);.
The extra 2>&1 redirects stderr into the output for me to see the issue.
The $out parameter showed the FontNotFound error that pygments was throwing.
I changed the font that Pygments used via the command line using: full,style=manni,cssclass=pygmentize_kbOKBd,font_name='DejaVu Sans Mono' -l php -o /srv/www/path/to/images/uploads/2513732976ad4b7.02729290.png /tmp/pygmentize_kbOKBd after finding which fonts I had available to me.
To see which fonts I had available to me as the user running the script, I just ran fc-list in an exec() command for Ubuntu, and checked the output of that for the list of available fonts.

PHP on IIS - Exec Returns 1

I have ImageMagick, IIS 6, Ghostscript, and PHP 5.3.1 installed on a Windows Server 2008 box and am trying to convert a PDF file into a JPG thumbnail.
However, it doesn't seem to be working-- the call to exec() produces a return code of 1 (which to my understanding, means that some general error has occurred). The output variable is simply an empty array. $output is simply an empty array. The same occurs if I use system() instead of exec()
Running the command from the command line seems to work, so my initial guess would be a simple permission issue... The directory is writable by PHP because the script that uploads a PDF to the directory works, and I have verified that everyone has permission to write to the directory as well.
Also, safe mode is off.
Any ideas as to what the issue could be?
Relevant code:
<?php
$output = array();
$ret = 0;
echo exec('convert D:\content\myfile.pdf[0] D:\content\myfile_thumb_1.jpg', $output, $ret);
var_dump($ret);
?>
Note: While I would test this on Apache on Mac OS X, I can't seem to get ImageMagick or Ghostscript installed correctly.
I've also ensured the following:
Correct case for the file names (all lowercase anyways)
Using the full path of convert.exe in addition to simply convert.exe
UPDATE:
After checking the task manager, convert.exe is being run and is taking up CPU time, suggesting to me that it is file permissions of some sort... I'm going to check it out now.
It turns out there was a permission issue with something in IIS-- the website ran under a different user than the command from CMD, which obviously results in it not working under IIS because it has lesser permissions than from CMD.

Lame encoder command in php shell_exec doesn't work via http server

I have a problem with running lame encoder via shell_exec script in php.
And the broke my problem to just this script and noticed that the script works if I run it via php command in terminal, but doesn't work if I open it in a browser.
I have permissios of all files set to 777 just in case.
here's the code
< ?php
exec('lame -f -V 9 ../furniture/sound/107887.wav ../furniture/sound/107887.ogg');
The thing is that script works if I run it in terminal with php command, but doesn't via browser.
Oh and this scirpt takes really max two seconds, so it coundn't be a timeout or anything. I also get no php or nginx errors.
How can I solve this?
Is lame on php's execution PATH? Try replacing lame with /usr/bin/lame or whatever.
How about the relative pathnames to the file arguments? Is ../furniture/ etc. correct from the current directory as seen by PHP? If in doubt, replace these with full pathnames too and see if that fixes the problem.
Less likely but worth mentioning: You might want to check that lame itself has all its executable bits set. If you own the file and it's only executable by the owner, apache won't be able to run it.
There may be many reasons why it is not working from the webserver, perhaps resource or permission related. You can find this out by using the second optional parameter of exec:
<?php
$output = "";
exec('lame -f -V 9 ../furniture/sound/107887.wav ../furniture/sound/107887.ogg',$output);
echo $output;
?>

Can't get shell_exec to download a file

I have a multithreaded cli downloader for ubuntu called Aria2c.
I've been trying to get a php script to run aria2c and download a file using shell_exec, but i can't seem to get it to work. Ultimately I plan to have an input box on a page where I can enter a link and aria would download it.
Here's the code I've come up with (for now im inputting the link manually):
<?php $dl = shell_exec('aria2c -d /home/user/ www.downloadlink.com'); ?>
Note that the aria2c command I specified works well in the shell; and the directory I'm attempting to download to is set to '777'.
I'm baffled as to why it's not working, any ideas?
PS: I prefer to use aria rather than the alternatives because it is multithreaded and it supports cookies.
Check if PHP is running in safe_mode. shell_exec won't work if safe_mode is on.
EDIT: aria2c was not referenced with a full path. Referencing it like this: shell_exec('/path/to/aria2c -d /home/user/ www.downloadlink.com') works.
I'll make the assumption that you are running PHP through a web server. In such case, it's very unlikely that the web server has permission to write into your user's home directory: Apache runs as daemon with the credentials of a limited user. Also, the PATH env variable in Apache is not necessarily the same as your user's PATH. Last but not least, you don't check the return value or the script output.
Try something like this:
<?php
exec('/path/to/aria2c -d /tmp www.downloadlink.com', $output, $return_var);
var_dump($output, $return_var);
?>
You can get the full path for aria2c with:
which aria2c

Categories