ffmpeg is not working in web hosting server - php

This is my code running in my local system, which works fine.
<?php
$ffmpeg = "C:\\ffmpeg\\bin\\ffmpeg";
//$ffmpeg = "/home1/doitteco/public_html/bishal/ffmpeg/bin/ffmpeg";
echo $ffmpeg."<br>";
$videoFile = "C:\\xampp\\htdocs\\Wildlife.wmv";
$audioFile = "convert2Mp3.mp3";
$cmd = "$ffmpeg -i $videoFile $audioFile";
echo $cmd."<br>";
if (!shell_exec($cmd)) {
echo "success";
} else {
echo "fail";
}
?>
And the following code is for the server:
<?php
//$ffmpeg = "C:\\ffmpeg\\bin\\ffmpeg";
$ffmpeg = "/home1/doitteco/public_html/bishal/ffmpeg/bin/ffmpeg";
echo $ffmpeg."<br>";
$videoFile = "/home1/doitteco/public_html/bishal/small.mp4";
$audioFile = "convertMp3.mp3";
$cmd = "$ffmpeg -i $videoFile $audioFile";
echo $cmd;
if (!shell_exec($cmd)) {
echo "<br>"."success";
} else {
echo "fail";
}
?>
I am not getting any error but the code is not working.It is not extracting the audio from the video file.

Please check your PHP configration settings from your C panel sometimes it may happen due to the exec_shell commands are disabled by your hosting server for security reasons.If you still are unable to do that please try change the URL of the image file use a relative path and surround it with quotes. For example:
$ffmpeg="path/to/your/ffmpeg.exe";
$video="path/to/video.mp4";
$audio="path/to/audio.mp3";
$cmd="$ffmpeg -i \"$video\" \"$audio\"";
if u are still unable to use ffmpeg then it may be because your hosting company do not allow that for the type of hosting you might have taken ,for that you need to upgrade your hosting type from shared hosting to VPS or dedicated hosting

Related

shell_exec() not working on php script

I wants to run shell_exec('youtube-dl -j ' . $url);, but it's not working on my PHP script and return blank array. When I try to run manually through cmd it's working fine.
I try localhost and also in my server but both are not working ... i already try many solution and implement it but still i can't.
Here is my PHP script
$url = clearString($this->security->xss_clean($this->input->post("url")));
$data['url'] = $url;
if(filter_var($url, FILTER_VALIDATE_URL)) {
$domain = strtolower(getDomainName($url));
$source = $this->DefaultModel->getSource($domain);
$data['source'] = $domain;
$cacheVar = "mediaInfo-".md5($url);
if(!$mediaInfo = $this->cache->get($cacheVar)) {
$mediaInfo = shell_exec('youtube-dl -j '.$url);
$this->cache->save($cacheVar,$mediaInfo,$source['linkCacheTime']);
}
}
When I execute $output = shell_exec("set"); it's return output i wants to run shell_exec('youtube-dl -j '.$url); command on my xampp server loaclhost.
Steps to resolve above issue.
upload youtube-dl in public_html directory.
provide full path like below
shell_exec('/home/{path}/public_html/youtube-dl -j
'.$url);

how to upload to files to amazon EC2

I am trying to upload files to an amazon EC2 from android. however whenever i go to upload the files I get a Unexpected response code 500 error. From what I uderstand this is because the user doesnt have the correct permissions to upload files to the database? I know that the problem is with the amazon EC2 instance rather than the code. but below is my php code for uploading to the server. first of all is that the correct way to enter the upload folder (/var/www/html/uploads) ? Any help on how i can get this working would be great.
<?php
if(isset($_POST['image'])){
echo "in";
$image = $_POST['image'];
upload($_POST['image']);
exit;
}
else{
echo "image_not_in";
exit;
}
function upload($image){
$now = DateTime::createFromFormat('U.u', microtime(true));
$id = "pleeease";
$upload_folder = "/var/www/html/upload";
$path = "$upload_folder/$id.jpg";
if(file_put_contents($path, base64_decode($image)) != false){
echo "uploaded_success"
}
else{
echo "uploaded_failed";
}
}
?>
Just a few notes:
First, you should make sure to send your data from the app with the enctype of multipart/form-data before submitting to the server.
Second, try variants of this simplified code:
if(isset($_FILES['image']))
{
$fileTmp = $_FILES['image']['tmp_name'];
$fileName = $_FILES['image']['name'];
move_uploaded_file($fileTmp, "/var/www/html/uploads/" . $fileName);
echo "Success";
}
else
{
echo "Error";
}
And finally, assuming you're using Apache and the user name is www-data, you'll need to make sure it can write to the upload folder:
sudo chown www-data:www-data /var/www/html/uploads
sudo chmod 755 /var/www/html/uploads

HTMLDOC does not execute from PHP

I am trying to create a PDF from an HTML file from a PHP page (Apache, LAMP) Wierd thing is, when I execute the script from the command line, it works and creates the PDF as expected. However when I browse to the page in my browser, it does nothing. I'm thinking it's a permissions issue somewhere, but I'm stumped! Here's the code. (NOTE the ls command DOES produce output in the browser so it's not just an issue of PHP not being allowed to execute shell commands)
<?php
$htmlName = ("output2/alex" . time() . ".html");
$pdfName = ("output2/alex" . time() . ".pdf");
$html = "<html><body><h1>Hello, World!</h1></body></html>";
$fileHandle = fopen($htmlName, "w+");
fwrite($fileHandle, $html);
fclose($fileHandle);
$command= "htmldoc -t pdf --browserwidth 1000 --embedfonts --header ... --footer t./ --headfootsize 5.0 --fontsize 9 --bodyfont Arial --size letter --top 4 --bottom 25 --left 28 --right 30 --jpeg --webpage $options '$htmlName' -f '$pdfName'";
echo "OUTPUT: \r\n";
$X=passthru($command);
echo "TESTING LS:";
$y=passthru("ls -al");
if(file_exists($htmlName) && file_exists($pdfName)) {
echo "Success.";
} else {
echo "Sorry, it did not create a PDF";
}
?>
When I execute the script from the command line it produces the expected output, and creates a PDF file like it's supposed to:
> php alextest.php
Zend OPcache requires Zend Engine API version 220131226.
The Zend Engine API version 220100525 which is installed, is outdated.
OUTPUT:
PAGES: 1
BYTES: 75403
TESTING LS:total 2036
drwxr-xr-x 9 ----- and so on...
When I browse the page in Chrome, it outputs only the LS command.
help!?
You might try using a full path as your php file my be executing in a different directory than it is saved in depending on how it is loaded. (IE via include, require, or .htaccess or directly by apache.)
IE
$htmlName = ("/home/alex/html/output2/alex" . time() . ".html");
$pdfName = ("/home/alex/html/output2/output2/alex" . time() . ".pdf");
I agree with the comments that using a package like http://dompdf.github.io/ or https://tcpdf.org/ would be best though.
I've seen the same issue, and for the life of me I simply couldn't find the answer to why it wouldn't do it from a web based call, but never a problem from the command line. So, instead of fighting my way to a solution on that front, I created a Perl proxy to allow me to parse PDFs from the command line making it useful for virtually any given purpose. For, with Perl, I've never had a problem parsing PDFs, and I've been doing it for decades now.
So, here's what you do. PHP Code:
exec("/usr/local/bin/perl5 -s /path/to/perl/executable/parse-pdf-from-html-document.pl -source=markup-file.html",$output);
foreach ($output as $aline) {
#- WAS SUCCESSFUL
if (strstr($aline,'Successful!') == TRUE) {
#- no feedback, win silently
}
#- NOT SUCCESSFUL
else {
echo $aline . "\n";
}
}
With $output holding the results of running exec.
Now let's look at the Perl code for parse-pdf-from-html-document.pl:
#!/usr/local/bin/perl5 -s
#- $document coming from commandline variable, via caller: PHP script
$myDocumentLocale = "/path/to/markup/document/".$document;
if (-e $myDocumentLocale) {
$documentHTML = $myDocumentLocale;
$documentPDF = $documentHTML;
$documentPDF =~ s/\.html/\.pdf/gi;
$myDocumentHTML = `cat $myDocumentLocale`;
$badPDF = 0;
$myPDFDocumentLocale = $myDocumentLocale;
$myPDFDocumentLocale =~ s/\.html/\.pdf/gi;
$badPDF = &parsePDF($myDocumentLocale, $myPDFDocumentLocale);
if ($badPDF == 0) {
print "Successful!";
}
else {
print "Error: No PDF Created.";
}
exit;
}
else {
print "Error: No document found.";
exit;
}
sub parsePDF {
my ($Ihtml, $Ipdf) = #_;
$wasBad = 0;
#- create PDF
$ENV{HTMLDOC_NOCGI} = 1;
$commandline="/usr/local/bin/htmldoc -t pdf13 --pagemode document --header ... --footer ... --left 1cm --size Letter --webpage -f $Ipdf $Ihtml";
select(STDOUT);
$| = 1;
#print "Content-Type: application/pdf\n\n";
system($commandline);
if (-e $Ipdf) {
$wasBad = 0;
}
else {
$wasBad = 1;
}
return $wasBad;
}
exit;

Php exec command pdftoimage not work

I have problem with my code.
My Code look like this:
$destinationFolder = $destinationRootFolder . '/';
// mkdir($destinationFolder,777);
$options = $this->buildOptions($saveAsJpeg, $inputPdf, $destinationFolder);
print_r($options);
// exit;
try {
$command = "/usr/bin/pdfimages ".$options[0]." ".$options[1]." ".$options[2];
echo $command;
// exit;
shell_exec($command);
exec($command);
// $command;
// echo $r;
} catch (ExecutionFailureException $e) {
throw new RuntimeException('PdfImages was unable to extract images', $e->getCode(), $e);
}
code entered first command before it executes it. When the copy command to the console everything works well but does not create php files png.
edit
root#mat-K50AB:~# php -a
Interactive mode enabled
php > ls
php > exec("/usr/bin/pdfimages -png /path/pdf/file.pdf /tmp/savefile/")
php > shell_exec("/usr/bin/pdfimages -png /path/pdf/file.pdf /tmp/savefile/")
php >
It also does not work
It sounds like the apache does not have permissions to run it, A few things to check
1) ( if CentOS/RHEL ) Is selinux stoping it, TO temporarly disable it
setenforce 0
Perminetly allow it ( Replace /usr/bin/pdfimages with all files that need access )
chcon -v --type=httpd_sys_content_t /usr/bin/pdfimages
2) Not executible by apache, Try
chmod +x /usr/bin/pdfimages
If nether of thoughs work, What os is your server running?

PHP's imagecreatefromstring function not working on Amazon Linux Server

I have created a script in which a i have to create a image at runtime using a 64bitencoded string .i m using imagecreatefromstring function of PHP but it works in my Windows XAMPP based PHP , but not on my cloud side applications which i deployed on Amazon cloud running SUSE version of Linux.
Can u give me any suggestion to overcome the problem.
Or is there any other function which is capable to create the image from the encoded string passed to it.
Thanks in adv
I am using following code
<?php
require ('../dbconfig/dbConfig.php');
$gameId = $_POST["gameId"];
$username = $_POST['email'];
$imagedata = $_POST['imagedata'];
$uploaddir = './../blogdata/i/';
$countSql = mysql_query("select max(_id) as fileName from blog_data ");
while($rowCommentData = mysql_fetch_assoc($countSql))
{
$num = $rowCommentData["fileName"];
$file = ++$num.".png";
$filedb = $uploaddir .$file;
}
/* $imagedata= 'iVBORw0KGgoAAAANSUhEUgAAABwAAAASCAMAAAB/2U7WAAAABl'
. 'BMVEUAAAD///+l2Z/dAAAASUlEQVR4XqWQUQoAIAxC2/0vXZDr'
. 'EX4IJTRkb7lobNUStXsB0jIXIAMSsQnWlsV+wULF4Avk9fLq2r'
. '8a5HSE35Q3eO2XP1A1wQkZSgETvDtKdQAAAABJRU5ErkJggg==';*/
$imagedata= base64_decode($imagedata);
if(($img = #imagecreatefromstring($imagedata)) !== FALSE)
{
if(imagepng($img,$filedb))
{
imagedestroy($img);
$sql="Insert into blog_data (game_id,text,type,username)".
"Values('$gameId','$file','i','$username')";
$result=mysql_query($sql);
if($result == 1)
{
echo $file;
}
else
{
echo "error2";
}
}
else {
echo "error1";
}
}
else
{
echo "error0";
}
?>
By running PHP info there i got this information
The PHP needs to have the libgd extension installed and loaded. Check phpinfo() if it's there. You probably can install it via yum. The package should be called php5-gd
From your code, it seems that you dont have the GD extension installed. Please check the phpinfo output and look for the GD extension
You will need root access to the server, which I don't think you get with Amazon's cloud service. You will need to recompile php with --with-gd flag.
http://www.php.net/manual/en/image.installation.php

Categories