PHP exec not giving the same result as cmd - php

exec ("C:/Lame/sox \"C:/1/2.wav\" -t wav \"C:/1/2.rev\" reverse");
Using that code to use an audio post processing tool to reverse a sound file. There is an output but the file is about 1/5th the size it should be and I am unable to play it. Basically it makes a file but its not the one I would have gotten if I did this in the command prompt:
C:/Lame/sox "C:/1/2.wav" -t wav "C:/1/2.rev" reverse
With that, I get the result I want and I am able to play the rev file.
Anyone have any idea why this is happening?

Found the problem. It was a permission problem.
All the other post processing command works because it writes in that folder. Reverse makes a temporary file in another folder which the current user didn't have write access in which why it made a small file since it tried to later read from a file that didn't exist.

Related

How to clear contents of file with batch script

I have a self-hosted local website (on W10) with a little chat application. The chat history is saved to a log.html file, and i want to clear it out with a batch script.
I know that on the Ubuntu Shell, it is as simple as > log.html but on Windows, that doesn't work.
I also found nul > log.html, but it says access denied
I also don't want to use a powershell script as i have to change executing rules and it takes nearly a minute.So, my question is:
Is there a way that i can empty log.html with a batch script that doesn't stay open for longer than 20 seconds?
Or, I don't mind if there is a way to use something php-related to clear it daily. I'm using IIS on Windows 10v1803 if that helps.
I think what you want is:
TYPE NUL > log.html
…or as possible alternatives:
BREAK>log.html
 
CLS 2>log.html
 
CD.>log.html
Technically they're not emptying the file they're writing a new file which overwrites the existing one.
This will delete the file and re-create it, and instantly close, so pretty much what you're wanting. Replace "Desktop" with the file path to the file, and place this .bat in the same folder as your log.html:
#echo off
cd "Desktop"
del "log.html"
echo. 2>log.html

file_get_contents failure on windows

I have a PHP CLI application that creates a file with file_put_contents then listens for changes to that file. If the filemtime changes then I try to get the content with file_get_contents. It often fails to retrieve the contents on windows. This baffles me. How is it possible that a process that creates the file cannot open the file?
I even ran icacls on the folder that the file is in and it still fails to have access to read the file that it created.
icacls.exe 'MYFOLDER' /grant MYUSER:(OI)(CI)F /T
Can someone please enlighten me on how to insure a PHP process can read a file it created?

How do i convert videos uploaded by user to .swf?

I am creating a website which enables to upload videos. But we know that user can upload any kind of video but the browser can't play them. So, I thought that I somehow can convert them into .swf and play them using a flash player. I tried to use ffmpeg-php but it didn't worked. my code was:
shell_exec('ffmpeg -i in.mp4 out.swf');
It does not show any error neither it returns out.swf.
Please! help me.
Things to check:
Does the in.mp4 file actually exist on the server and is it in the
correct temporary folder?
Check that file size limits (upload_max_filesize PHP setting) are
not being hit.
Does the ffmpeg command work properly from a shell promt as the
user that the webserver is running as? (this test should be
performed in the folder where you are processing the file) Use the
verbose logging options to check for errors
Capture all the output from the shell_exec and check for errors.
Try using system or exec where you can also capture the return
value of ffmpeg which can then be used for error checking
Finally, I would specify actual directory names for the input and output files. This will narrow down problems as you know exactly what folder to look in for results. You can also adjust permissions if required

Batch script to download and save XLS file to directory

I am trying to write some batch script to download and save an XLS file from a URL. I am able to down load the file by using
#ECHO OFF
start /d "C:\Program Files\Internet Explorer" IEXPLORE.EXE url link
exit
I would now like to save these files to a folder or directory.
Any help anyone could provide here would be greatly appreciated.
There are at least two ways to do it.
Like Buddy suggested, use a command-line downloader, for example wget.
Under Linux, you can run PHP directly (even without a webserver). See PHP: Command Line PHP on Microsoft Windows in PHP manual.
Don't run a browser, or - even worse - IE, just to run a PHP script.

Executing PHP script via SSH

I want to send data to my server via SSH. The data is image files that need to be saved into directories on the server.
If I run the script via SSH how can I get a PHP script to read the image files?
For example, if I used bash I could do
./uploadimage.bash -image.jpg
and that would be that. But my knowledge of PHP is limited. Usually PHP uses the $_FILE array when dealing with files, as far as I know. Do I need to use this if I send the files by SSH?
Run the script via php command line executable:
php myscript.php image.jpg image2.jpg
You can the get the file names via $argv array and deal with them any way you please.
It depends on what you need to do with the images.
Do you just need to echo them out to the user?
echo file_get_contents('image.jpg');
Are you meaning to retrieve the command-line variables passed to the script? Use $argv.
myScript.php image.jpg # image.jpg becomes $argv[1]
Do you need to do processing on the images? Use the GD functions.
$image = imagecreatefromjpeg('image.jpg');
// Do processing
imagejpeg($image); // Pass a filename if you want to save it instead of output it.
If you want to simply upload a bunch of files to a remote server, your best bet is to use scp command, rather than PHP
scp /your/file.png username#host:/remote/path.png
If you execute a PHP script through an SSH Session, there's no way you can send a file through SSH. You have to first copy it to the remote server and then execute the PHP which uses file_get_contents or something like that.
If you are sure that PHP must be the recipient of the file (maybe you want to do some logic to determine the file name, path), you have to host it as a webserver, and you can use curl to upload the file, like this:
curl -k -F myfile=#image.png foo.php.

Categories