Command line cannot fwrite, browser can [message #174561] |
Fri, 17 June 2011 21:22 |
Adrienne Boswell
Messages: 25 Registered: October 2010
Karma:
|
Junior Member |
|
|
Okay, I give up! I pulled the very last hair out of my head, and now I
am asking for help.
This is a Win2003 SP2 server running Plesk PHP5 on Microsoft-IIS/6.0.
Why am I using PHP on Win? The main application was written in Classic
ASP, hence the Windows server. I need to run a script from the command
line so I can call it with the task manager to run every night.
Using the command line, the script gives a warning, and then fails saying
it cannot write to a file. Using a browser, the script works flawlessly.
I am thinking it might be a permission issue? I checked and IUSER the
DOMAIN USER, SYSTEM and Administrator have full permissions on the file
(s) in question. Is there another user I should be including? The batch
file is running as Administrator.
The other issue is that the file giving a warning IS on the server. All
the other files mentioned are found without a problem - and again this
only happens with the command line.
This is the error I am getting:
C:\Inetpub\vhosts\aloyaltycard.com\httpdocs\groupmail>cd c:\parallels
\plesk\additional\pleskphp5
C:\Parallels\Plesk\Additional\PleskPHP5>php.exe c:\inetpub\vhosts
\aloyaltycard.com\httpdocs\groupmail\groupmail.php
Warning: file_get_contents(groupmail1_noname.txt): failed to open stream:
No such file or directory in C:\Inetpub\vhosts\aloyaltycard.com\httpdocs
\groupmail\groupmail.php on line 88
cannot write to groupmail.html
Here also is the contents of the folder in question:
Volume in drive C has no label.
Volume Serial Number is E454-BB08
Directory of C:\Inetpub\vhosts\aloyaltycard.com\httpdocs\groupmail
06/17/2011 01:15 PM <DIR> .
06/17/2011 01:15 PM <DIR> ..
06/17/2011 12:37 PM 3,102 groupmail.html
06/17/2011 01:13 PM 5,515 groupmail.php
06/10/2011 05:50 PM 485 groupmail1.txt
06/10/2011 05:51 PM 443 groupmail1_noname.txt
06/10/2011 05:50 PM 93 groupmail1_txt.txt
06/10/2011 05:50 PM 1,838 groupmail2.txt
06/10/2011 05:50 PM 1,858 groupmail2_candidates.txt
06/10/2011 05:50 PM 1,082 groupmail2_customers.txt
06/10/2011 05:50 PM 834 groupmail2_nonames.txt
06/10/2011 05:50 PM 1,515 groupmail2_txt.txt
06/17/2011 12:37 PM 3,122 groupmail_candidates.html
06/17/2011 12:37 PM 2,346 groupmail_customers.html
06/17/2011 12:37 PM 2,056 groupmail_nonames.html
06/17/2011 12:36 PM 138 groupmail_prepare.bat
Just for shits and giggles, here's the contents of my batch file as well:
@echo on
cd c:\parallels\plesk\additional\pleskphp5
php.exe c:\inetpub\vhosts\aloyaltycard.com\httpdocs\groupmail
\groupmail.php
Here is the relavent PHP:
$filename = "groupmail.html";
$file_candidate = "groupmail_candidates.html";
$file_customers = "groupmail_customers.html";
$file_nonames = "groupmail_nonames.html";
$groupmhtml1 = "groupmail1.txt";
$groupmhtml1noname = "groupmail1_noname.txt";
//this above file is the one it cannot find
$groupmhtml2 = "groupmail2.txt";
$groupmcandidate = "groupmail2_candidates.txt";
$groupmcustomers = "groupmail2_customers.txt";
$groupmnonames = "groupmail2_nonames.txt";
$groupmail = fopen( $filename,'w' ) or die( 'cannot open
groupmail.html' );
$candidates = fopen( $file_candidate,'w' ) or die ( 'cannot open
groupmail_candidates.html' );
$customers = fopen( $file_customers,'w' ) or die( 'cannot open'.
$file_customers );
$nonames = fopen( $file_nonames,'w' ) or die( 'cannot open'.
$file_nonames );
$group1 = fopen( $groupmhtml1,'r' ) or die( 'cannot open
groupmail1.txt' );
$group2 = fopen( $groupmhtml2,'r' ) or die( 'cannot open
groupmail2.txt' );
$firstpart = file_get_contents($groupmhtml1);
$firstnoname = file_get_contents( $groupmhtml1noname );
//warning comes right here
fwrite( $groupmail,$firstpart ) or die( 'cannot write to
groupmail.html' );
//failure occurs right here
fwrite( $candidates,$firstpart ) or die ( 'cannot write to
groupmail_candidates.html' );
fwrite( $customers,$firstpart ) or die( 'cannot write to'.
$file_customers );
fwrite( $nonames,$firstnoname ) or die( 'cannot write to'.
$file_nonames );
$sql = "SELECT merchant, address1, line2, phone, email, uri,
primarycategory, pricategory_id, merchant_ipk, coupon_id, printsleft,
validto, amount, dollarpercent, image_path FROM madecoupons WHERE status
<> 'D' ORDER BY id DESC LIMIT 2";
$rs = db_query( $sql );
$insert = "INSERT INTO madecoupons_mailed (merchant_id, email)
VALUES ";
while ($row = mysql_fetch_array($rs,MYSQL_NUM))
{
$merchant = str_replace( "~","'",$row[ 0 ] );
$address1 = $row[ 1];
$line2 = $row[ 2];
$phone = $row[ 3];
$email = $row[ 4];
$uri = $row[ 5];
$category = $row[ 6];
$catid = $row[ 7];
$merchant_id = $row[ 8];
$coupon_id = $row[ 9];
$maxprints = $row[ 10];
$description = "Get 10% off!";
$exceptions = "";
$validto = $row[ 11];
$amount = $row[ 12];
$dollarpercent = $row[ 13];
$image_path = $row[ 14 ];
$linetowrite = "<div style=" . chr( 34) . "float: left; font-
size: 70%; margin: 0 1em .5em 0; width: 200px; background-color:#fff;
padding:0 .5em 0 .5em; border:1px solid #c0c0c0; text-align:center;" .
chr( 34) . "><h2><a href=" . chr( 34 ) .
"http://aloyaltycard.com/coupon.asp?sid=" . $coupon_id . chr( 34 ) .
">" . $merchant . "</a></h2>" .$image_path . "<br />".$description ."<br
/>".$exceptions . "<br /></div>";
//echo $linetowrite;
fwrite( $groupmail,$linetowrite );
fwrite ( $candidates,$linetowrite );
fwrite ( $customers,$linetowrite );
fwrite( $nonames,$linetowrite );
$insert = $insert . "( ".$merchant_id.",'".mysql_real_escape_string
($email)."' ),";
}
mysql_free_result($rs);
$lastpart = file_get_contents( $groupmhtml2 );
$lastcandidate = file_get_contents( $groupmcandidate );
$lastcustomers = file_get_contents( $groupmcustomers );
$lastnonames = file_get_contents( $groupmnonames );
fwrite( $groupmail,$lastpart );
fwrite( $candidates,$lastcandidate );
fwrite( $customers,$lastcustomers );
fwrite( $nonames,$lastnonames );
$insert = substr( $insert,0,strlen( $insert )-1 );
db_query( $insert );
mysql_close( );
--
Adrienne Boswell at Home
Arbpen Web Site Design Services
http://www.cavalcade-of-coding.info
Please respond to the group so others can share
|
|
|