I'm using flare to decompile a flash movie. I need to do it via PHP. User visits PHP script, it decompiles the flash movie.
Here is how the files are set up on my web host:
index.php:
<?php
error_reporting(-1);
echo shell_exec('./flare movie.swf');
?>
Flare is supposed to create a file named movie.flr once the script runs, but there is no such file. I am thinking my shell_exec is wrong.
phpinfo() - http://zachafer.com/phpinfo.php
You're trying to execute the wrong file.
flare.tgz is an archive (not executable) containing the flare binary (executable).
Unpack it with an archiver tool like winrar on windows or tar on linux (tar xvf flare.tgz).
Inside the archive, you will find a file named flare. Try with this one and it might work if your host provider allow the shell_exec() function calls.
You can't execute a .tgz file directly! You need to unpack the executable before you can run it.
This function is disabled when PHP is running in safe mode... check it or ask your host provider about it
I think flare.tgz is not an executable but a .tar.gz file (it's like a zip file, but it is another format).
You have to unpack it first !
Related
On a shared server with ffmpeg installed above the webspace. Example: /home/username/ffmpeg/ffmpeg which is the full address all the way down to the executable.
The problem is that php cannot find ffmpeg using the -verson option. We tried using mod rewrite to a php file in the public_html webspace which then includes the ffmpeg address above the webspace. But that did not work.
I have never dealt with ffmpeg installed this way, its always been installed in /usr/bin/ or /usr/local/bin .
is there a htaccess or php ini command to tell php where ffmpeg is installed?
how does php suppose to access ffmpeg installed in this way, it is installed as an alias?
Thanks so much :)
As php and ffmpeg are separate things, there's no guarantee that your host will allow php to run ffmpeg, however here are some things you can try:
You can check if web server's user (which php runs as) can "see" any ffmpeg executables in its path by running:
<?php echo shell_exec("which ffmpeg"); ?>
If the output is empty, ffmpeg isn't in the path of the web server's user. In this case you still might be able to run it, if you know the path of the executable.
Also if you run:
<?php phpinfo(); ?>
That will tell you if php is running in safe mode. If it is, your web host may have locked down php's ability to do potentially dangerous things such as executing shell commands.
Change Permission of binaries files (ffmpeg.exe and ffprobe.exe) to 0744.
See image sample here:
I am sorry if this question was answered.
Why can't I run php code directly without using terminal on mac.What I mean when you double click on html file it automatically opens in the browser but not in the case of php.If I try to double click on php it opens with some text-editor.
Any help would be helpful.
Try this (for mac),
Open terminal
cd to folder
Start php server - php -S 127.0.0.1:8000
Open browser and enter - http://localhost:8000/file-name.php
I think you don't understand what PHP is ...
HTML is a markup-language, that can directly be understood by the browser. If the browser opens the file, it can do something with the content.
As PHP is a programming-language, you need a parser. This parser is your PHP executable. This program can understand PHP and does nothing more, than running the code and giving something as result. This result may be an HTML webpage, an image or whatever.
Since you said, you're using a mac, here's a quick introduction on how to set up your personal webserver:
On Mac OSX, PHP and Apache (that's what I use in this example) is already installed and pre-configured. You can just start using it like this:
Go into your system preferences and verify that Web Sharing is enabled.
Open the Finder and go to /Library/WebServer/Documents/localhost. All files that are in there are processed by the local webserver (Apache and PHP, if you want to know that). Place your file in there and open your webserver and call http://localhost/YourFile.php and it will call the file YourFile.php and show you what the output of the script is.
EDIT:
If you are using PHP for scripts, like bash-scripts, see the answer #andreas-baumgart provided.
To run PHP in MAC, one should start the built-in Apache Web server and also enable the PHP already installed.
This can be done with the following steps.
Go to /etc/apache2/httpd.conf and change the permission to sudo chmod 777 httpd.conf
Then open the above file to uncomment the line #LoadModule php5_module libexec/apache2/libphp5.so
To start the apache built-in server, use the command sudo apachectl start in the terminal.
Now .php files can be created and run from the terminal using php -f filename.php and it can also be run on a browser using http://localhost/filename.php
You cannot execute plain PHP scripts as they are no executable programs but source code. As such they contain just the receipt for an interpreter to create executable code. In order to run your PHP script you need to pass it to the PHP interpreter. In your scenario you can archive that by providing a shebang.
To run your script on double click try this:
Make the script executable using chmod +x yourscript.php
Prepending the according Shebang to the files content: #!/usr/bin/env php.
Select a PHP file in Finder, hit CMD-i and change "Open With" to "Terminal.app".
Late response, but was looking into doing this for myself, this coming up as one of the results in my searching wanted to provide 2 solutions since I ultimately came to both on my own.
Solution #1
The simple way is to go a round about way by writing a wrapper file to execute the script you're working on. Create a file with the following code:
#!/usr/bin/php
<?php
include('name-of-php-script.php');
?>
Save it as wrapper.command The name wrapper isn't important, but the command extension tells Finder that this is a shell script to open up in Terminal. The file itself just executes whatever php script is in the include.
Solution #2
The specific inquiry requires a bit of work.
First make sure that the 1st line of the php script is:
#!/usr/bin/php
This is where the preinstalled version of PHP is installed on Mac OS X. You can always verify by running this command in terminal:
whereis php
Once you've added the Shebang line to the php script you've readied it for automatic execution.
To make it double clickable executeable you have to do the following:
Right click on the PHP script and click Get Info. Click where it says Open With, click the default option to see all the available options. Select Other...
Switch where it says Enable: from Recommended Applications to All Applications, and click the checkbox for Always Open With. Choose Terminal as the application. Finally, you have to click the button that says Change All...
OS X will verify you want it to set Terminal as the default application to open .php files
This will make every php file open up in terminal by default, but unless they contain the #!/usr/bin/php line they won't actually run.
Try MAMP
MAMP 4 brings even more opportunities for web developers. We are now supporting MySQL 5.6 and Nginx is now fully integrated. Server starting times have been improved.
Because .php files are not 'executable' per se, instead they are just text files with a PHP extension.
You need to run the php interpreter against the file to execute on it's contents.
My setup is as follows: Windows 7, XAMPP with Apache and PHP enabled I have a PHP script in which I call an external program to do run a conversion. This external program is an EXE file, which requires 3 attributes:
The source file
The destination file
Additional flags (conversion type etc)
When I use the command line tool built into XAMPP to execute my script, everything works fine. But when I use the exec() function in my PHP script, no output file is created. I'm pretty sure the conversion is actually happening (it takes about 5 seconds, about the same time it takes to run the PHP script).
I think it's a permissions thing, so I already moved the EXE file to the same folder as my PHP file and adjusted the permissions of the entire folder (I granted all permissions to all users). I also disabled the Windows UAC and tried to put the command in a BAT file. The file just is not created.
Any help or tips would be greatly appreciated!
My PHP code is as follows:
exec('c:\converter.exe c:\src.txt c:\dst.txt -f', $output);
print_r($output);
When I print out $output, the array turns out to be empty. When I put the exact same command in Command Prompt, the code works like a charm (no syntax errors). I use absolute paths as well.
Try to copy your executable file in same folder as your application.
try
exec("script.exe src.txt dst.txt", &$output);
echo $output;
also, do not forget to use escapeshellcmd() to add some security to your application.
Thank you very much for your input! As it turns out, it was Windows issue caused by the 'Interactive Services Detection' feature. Apache was running as a system service, which prevented calls to external programs (with a GUI). I disabled the run-as-service feature in XAMPP, which solved the problem. A more thorough explanation can be found here: http://php.net/manual/en/book.exec.php
I wrote a PHP script, which is creating some files.
After it finished i want it to open a folder, where the created files stored.
exec("explorer C:\\test");
Unfortunately it isn't open the folder at all.
I check it in cmd as well where it is working.
I also tried this:
shell_exec("explorer C:\\test");
Any hint or advise is greatly appriciated.
This can be done if your localhost is on your computer with windows operating system (I use xampp). Any cmd command will work with exec();
So for your question:
$path = "C:\your path";
exec('start "" "'.$path.'"');
Will open your folder in windows.
Why not use PHP's directory functions?
http://php.net/manual/en/function.dir.php
http://php.net/manual/en/function.readdir.php
I'm guessing that PHP can't open a GUI program, such as explorer, as it may not be able to access the user's display. Just my theory anyway. You could build a folder GUI using PHP and the aforementioned functions.
I simply want to 'rar' a folder with the help of PHP. There are 2 ways to do this. One is via shell_exec or exec, which isn't working for me, although shell_exec and exec are enabled on the server and working for other commands.
The other method is via .sh file, but I don't know how to use it properly :(
I need some code which works properly for this.
I'm trying to use this command:
rar a -v100m -m0 /home/admin/somefolder.rar somefolder-to-rar
It's Ubuntu 9.10
if other shell commands work then rar should.
is rar.exe on the path on the machine? or are you specifying the full path to rar.exe in your command?
Check the working directory, and try using passthru to display any error from the output
With php you can use backticks (``) to execute a command (from php.net)
I'm not sure what it would be to rar, but zip would be:
<?php
`cd $dirToZip; zip -pr $nameOfZipFile *`
?>
Assuming your command is correct and rar is accessible from cli the backticks should work.
You likely have a permissions problem. Check to make sure that whatever user PHP is running as has access to execute RAR.
Also, follow Sam's suggestion of using the full path. Your standard path may be specific to your user account, which may be different for the user PHP uses.