I'm trying to run this simple script:
<?php
$PHP_PATH = "c:\Program Files (x86)\PHP\\";
$CLIENTPATH = dirname(__FILE__)."\Client.php";
$SERVER = "http://localhost:8080/mobile/Server";
$handle = popen("C:\WINDOWS\system32\cmd /C start ".$PHP_PATH." -f ".$CLIENTPATH." ".$SERVER, 'r');
?>
But I always get this Windows messagebox error:
Windows cannot find c:\program. Please make sure you typed the name correctly and then try again.
Searching on google I also find this thread about this error, but the meassures are I litlle drastic I guess.
So the problem its in my code ? Or there can be something else wrong ?
Thanks.
You need to escape the whitespaces in $PHP_PATH = "c:\Program Files (x86)\PHP\\";!
Related
I've been trying to run a php file using window task scheduler. I've tried using the .bat file, but it won't work.
Here's what I've done:
I've created a task "Download Image"
I've created a .bat file, and the content is:
"C:\xampp\php\php.exe" -f "D:\server\newxml\download.php";
The php file that I want to run is:
ini_set('max_execution_time', 300);
$doc = simplexml_load_file('xml_edit_feeds.xml');
foreach ($doc->xpath("//item") as $item) {
$name = $item->productname;
$realname = preg_replace('/\s/', '',$name);
$url = $item->thumbnail_url;
$img = 'D:/server/newxml/imagethumbnail/'.$realname.'.png';
$filename = 'D:server/newxml/imagethumbnail/'.$realname.'.png';
file_put_contents($img, file_get_contents($url));
}
?>
This is the screen shoot of the windows task scheduler:
Is there something wrong from what I did? Thank you for your help
I didn't try this before, but I think you should use a browser exe program to open your webpage instead of php.exe.
Eureka! I got the answer to this, so, I what I've done is:
Set the Program/Script to: C:\xampp\php\php.exe
Set the arguments to: D:\path\to\php.php (In my case D:\server\newxml\download.php)
Set the start-in to the folder that contains download.php (php file that you want to run). In my case: D:\server\newxml\
I am a beginner in PHP. I am writing a file program, but before I could properly use the logic and code it, I got stuck here.
I am writing this PHP program in Linux Ubuntu Terminal. Please don't worry about what I am trying to do with the program. Just helping me understand the error itself would be a great help.
I have a PHP file(a.php) with the following contents:
<?php
$input=fopen($argv[1],"r");
$col=$argv[2]-1;
while(!feof($input))
{
$x=fgets($input);
$array=explode("\t",$x);
}
fclose($input);
?>
Now when I give this in the command prompt:
php a.php 1
I should be getting nothing as an output, but I get around 3 to 4 blank lines. Can anybody tell me why?
The problem must be your file path that is $argv[1].
Try this
$filePath = 'Your file path here';
if( !#$input = fopen($filePath, "r") ) {
die("Could not open $filePath");
}
while(!feof($input))
{
$x=fgets($input);
$array=explode("\t",$x);
}
fclose($input);
I'm writing a code to SCP a file from Solaris 10 machine to a router (couldn't be simpler).
Here is the code:
<?php
$src = "test.txt";
$trg = "test.txt";
echo "Connecting...\n";
$connection = ssh2_connect('myrouter',22);
echo "Authenticating...\n";
ssh2_auth_password($connection, 'mylogin', 'mypassword');
echo "Sending...\n";
ssh2_scp_send($connection, $src, $trg);
?>
This works just fine but the remote filename is screwed up:
10/11/2012 10:57p 15 'test.txt'
Note the single quotes around the file name test.txt.
When I use Solaris SCP everything works fine. Here is the command:
solaris10$ scp test.txt mylogin#myrouter:test.txt
The remote file name looks like:
10/11/2012 11:10p 15 test.txt
So the problem seems to be limited to PHP.
Did anybody have similar issue? Where should I start looking?
The remote filesystem is FAT32.
Thank You,
PN.
I had the same problem when using ssh2_scp_send(). However, I switched to using ssh2_sftp() and fwrite() and the problem went away. See examples in the comments on the http://www.php.net/manual/en/function.ssh2-sftp.php page.
The bottom comment on this page http://www.php.net/manual/en/function.ssh2-scp-send.php refers to a problem you might be having;
Can you set $trg to the full remote server path?
$trg = "/var/www/test.txt";
or
$trg = "/test.txt";
I am trying to make a cron job via my websites cpanel. I have talked to the support services and they gave me this command to run to execute a php file on my website.
/usr/local/bin/php -q /home/mymcstatus/domains/mymcstatus.net/public_html/redesign/scripts/update.php
This doesnt seem to work though, I have also set the minute interval to every minute using */1.
I am using the code below inside of the file update.php:
<?php
ini_set('display_errors', 1);
ini_set('log_errors', 1);
ini_set('error_log', dirname(__FILE__) . '/error_log.txt');
error_reporting(E_ALL);
require('minequery.class.php');
include('../config/config.php');
$date = date("D-M-Y");
$file = fopen("UPDATE_LOG($date).txt", 'w');
$query = mysql_query("SELECT * FROM servers") or die(mysql_error());
if($query) {
while($row = mysql_fetch_array($query)) {
$ip = $row['ip'];
$port = $row['port'];
$name = $row['name'];
$string = "[UPDATE LOG]: $date - Updated Server $name \n";
fwrite($file, $string);
print("[UPDATE LOG] Updated Server $name </br>");
}
mail("duncan#mymcstatus.net","UPDATED","Server has updated","From: Mymcstatus");
} else {
print("Cant query");
}
?>
When I go to update.php manually through the web browser that code works, but nothing seems to happen with the Cronjob. What am I missing or doing wrong?
There are a few things that could be going on here. The first is to check the file permissions of update.php and make sure it is executable. The cron may be executing as a different user that doesn't have permission to execute update.php. The 2nd thing you can try is including this as the very first line of update.php with no whitespace before it.
#!/usr/local/bin/php
Usually cron jobs aren't run from the same directory where your PHP lives so it's possible that it is running but the output file is being created elsewhere. Try changing the output file path to be the full path to the file, i.e:
$file = fopen("/home/mymcstatus/domains/mymcstatus.net/public_html/redesign/scripts/UPDATE_LOG($date).txt", 'w');
With the help of the above comments I managed to fix the file paths but it also came down to the command. I had put the wrong user path in here is the command that works.
/usr/local/bin/php -q /home/mymcstat/domains/mymcstatus.net/public_html/redesign/scripts/update.php
Thanks for the help
It's always a good idea to cd to your script's path. This way you don't need any change in the name of the include and require files and any other file names engaging in file operations. Your cronjob command could look like this:
cd /home/mymcstatus/domains/mymcstatus.net/public_html/redesign/scripts/; /usr/local/bin/php -q /home/mymcstatus/domains/mymcstatus.net/public_html/redesign/scripts/update.php
You don't need to supply any absolute file paths this way.
Ok Guys I am working on it since yesterday, and this is driving me crazy.
I am creating a way to upload and zip a file on the fly, but also this zip should be then password protected (customer request, unfortunately).
Now everything is fine until the password protection, that is not working at all.
I know exec is so unsafe, but trust me, I just want to have a solution right now.
This is the code
if(isset($_FILES['fileSound']['name']) && isset($_FILES['fileLyric']['name'])) {
$nameFileSound = $_FILES['fileSound']['name'];
$tmpNameSound = $_FILES['fileSound']['tmp_name'];
$nameFileLyric = $_FILES['fileLyric']['name'];
$tmpNameLyric = $_FILES['fileLyric']['tmp_name'];
$download_folder = './CopyrightFiles/';
$zip = new ZipArchive();
$fileconpress = $download_folder . $RefNum . ".zip";
$conpress = $zip->open($fileconpress, ZIPARCHIVE::CREATE);
if ($conpress === true)
{
$zip->addFile($tmpNameSound, $nameFileSound);
$zip->addFile($tmpNameLyric, $nameFileLyric);
$zip->close();
echo $fileconpress."<br/>";
echo "yess !! Success!!!! ";
}
else echo " Oh No! Error";
}
exec("zip -r ".$download_folder.$RefNum.".zip -P password ".$download_folder.$RefNum."-protected.zip");
Now $RefNum is a string like this 1333-COP-3899827399283.
I checked if the command exec is up on the server and yes it is.
No errors show up.
What am I doing wrong?
Maybe the path?
What path should I use for the exec command?
For example the $zip option start from the public_html
Where the exec starts?
Do you think is that the problem or is there any other issue?
Please help me.
Thank you!
For one thing you need to change the argument order:
exec("zip -P password $download_folder$RefNum-protected.zip $Orig.zip");
Btw there seems no way with the common Unix zip command to update the zip file. You will repackage the original zip file as another password-protected zip file here.
If that fails, then look into the error.log for clues. Or use print exec(...) after adding 2>&1 behind the command to see all error messages.