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);
Related
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
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?
I have full root access through VPS (CentOS).
In Unix shell I am able to extract images with following command:
pdfimages -j xyz.pdf images
But I am unable to execute the command through PHP
exec ("pdfimages -j xyz.pdf images");
xpdf is installed. Also I have checked that // Exec function exists; // Exec is not disabled; // Safe Mode is not on.. by using following code:
$exec_enabled =
function_exists('exec') &&
!in_array('exec', array_map('trim', explode(', ', ini_get('disable_functions')))) &&
strtolower(ini_get('safe_mode')) != 1;
if($exec_enabled) { echo "enabled"; }
The following is however getting executed properly:
exec("ls -1 *.php", $output);
foreach ($output as &$tmp){
echo "$tmp<br>";
}
What am I doing wrong? Where is the issue?
You need to specify the path like below , this will save each image in the folder of your PDF.
'image' is just the file name ..
$path = 'path/to/your/folder/';
$pdf = $path.'xyz.pdf';
$command = 'pdfimages -j '.$pdf.' '.$path.'image';
exec($command);
I have a shell script that uses unoconv and then pdftk. when i run the script through the command line it works exactly how i want it to. When i use shell_exec($cmd) in php with the same exact command it runs the script (i know because of the echo's in the script) but it looks like it does not use unoconv (and therefore cannot use pdftk). Any idea on how to troubleshoot this problem? here some code:
if(isset($_FILES["file"]["name"]) && !empty($_FILES["file"]["name"])){
$fname = $_FILES["file"]["name"];
$tmp_name = $_FILES["file"]["tmp_name"];
$dir = "powerpoints/".$name."/";
$ispdf = "1";
$output = shell_exec('mkdir '.$dir);
chmod($dir, 0777);
echo $output;
if(move_uploaded_file($tmp_name, $dir.$fname)){
chmod($dir.$fname, 0777);
$cmd = 'importppt.sh '.$name.' '.str_replace(".ppt", "", $fname);
echo "\n".$cmd;
$output = shell_exec($cmd);
echo $output;
}else{
$message = "move_uploaded_file() Failed";
}
and here is the shell script
#!/bin/bash
echo $1 ' is the argument:' $2 ' is the second '
STRING="/var/www/html/devclassroomproject/powerpoints/"
echo $STRING$1/$2'.ppt '
unoconv $STRING$1/$2'.ppt'
pdftk $STRING$1/$2'.pdf' burst output $STRING$1/$1'_%2d.pdf'
This is what is printed from echos:
importppt.sh pptest pptestpptest is the argument: pptest is the second
/var/www/html/devclassroomproject/powerpoints/pptest/pptest.ppt
edit:
to decipher my debugging
the command: "importppt.sh pptest pptest"
importppt.sh being the shell script; pptest is the first and second argument
printed by the first echo in the shell script: "pptest is the argument: pptest is the second"
printed by the second echo in the script verifying the complete path of the pdf which does exist: "/var/www/html/devclassroomproject/powerpoints/pptest/pptest.ppt"
sorry for the confusion
Found out what was wrong. the answer is here
http://johnparsons.net/index.php/2013/08/05/how-to-keep-unoconv-apache-from-making-you-sad/
basically you have to set up a home directory for the user for apache2 as www-data and change the path to the shell in the passwd file
he doesnt mention it but the changes will not work unless you restart apache
I'am using CutyCapt on my CentOS.
It works fine via terminal but it doesn't work via php exec function.
I've started xvfb by command in terminal:
Xvfb :99 -screen 0 1024x768x24
And I'am trying to do a screenshot by php script:
exec("DISPLAY=:99 /path/to/cutycapt --url=<some url> --out=<path/to/output>");
It doesn't show any errors but there is no output file (output directory has chmod 777)
Can somebody help me?
Thanks
UPD:
Maybe it is better somehow to allow executing of Xvfb by Apache?
I've managed to get CutyCapt to run successfully using the php at the end. The $_parameters are passed via AJAX to the php script. Hope this helps...
case 'Output_Chart': {
// We always create the .png. We use the ImageMagick convert (IMC) command to make .pdfs
if ($_Suffix == 'pdf') {
$IMC = ";convert -page 735x850 '$_PathOut/$_ChartName.png' '$_PathOut/$_ChartName.pdf'";
} else {
$IMC = '';
}
// Prepare the query string for the CutyCapt URL
$sQuery_Pattern = '?Path=%s&iDL=%d';
$sQuery = sprintf($sQuery_Pattern, $_Path, $_iDL);
// Prepare CutyCapt's command and parameters (NB: query string and out parameter are enclosed in aposts for the shell)
$sCC_Cmd = '/var/www/LF/Includes/CutyCapt';
$sCC_URL = "http://localhost/LF/LFPrint.html'$sQuery'"; // Note: Inner apostrophes
$sCC_Out = "'$_PathOut/$_ChartName.png'";
$sCC_Pattern = ' --url=%s --out=%s --delay=%d --min-width=%d';
$sCC_Options = sprintf($sCC_Pattern, $sCC_URL, $sCC_Out, $_Delay, $_MinWidth);
//$sCC_CmdLine = $sCC_Cmd . $sCC_Options . " 2> CutyCapt.err.txt";
$sCC_CmdLine = $sCC_Cmd . $sCC_Options . " 2> /dev/null";
// Prepare the final command line with xvfb-run, CutyCapt, and the URL?QueryString
$sCC_CmdLine = 'xvfb-run --auto-servernum --server-args="-screen 0, 800x1000x24" ' . $sCC_CmdLine . $IMC;
exec( $sCC_CmdLine, $aOutput = array(), $ret);
// Wait for and then return the results. sCC_CmdLine and aOutput are just for debugging
echo json_encode(array("ret" => $ret, "cmd" => $sCC_CmdLine, "Output" => $aOutput));
break;
}