LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 08-16-2010, 08:13 PM   #1
steve51184
Member
 
Registered: Dec 2006
Posts: 381

Rep: Reputation: 30
trying to append data to a file with php/fwrite


hi all i'm trying to make a quick and simple '.htaccess' installer and i'm using fopen/fwrite to do this but i'm getting an error:

Quote:
Parse error: parse error in /var/www/test.php on line 12
here's the code:

Code:
<?PHP
$File = ".htaccess";
$fh = fopen($File, 'a');
$Data = "\n#test write
<IfModule mod_deflate.c>
   AddOutputFilterByType DEFLATE text/css
   AddOutputFilterByType DEFLATE text/javascript application/javascript application/x-javascript text/x-js text/ecmascript application/ecmascript text/vbscript text/fluffscript
   AddOutputFilterByType DEFLATE image/svg+xml application/x-font-ttf application/x-font font/opentype font/otf font/ttf application/x-font-truetype application/x-font-opentype application/vnd.ms-fontobject application/vnd.oasis.opendocument.formula-template
   AddOutputFilterByType DEFLATE text/xml application/xml
</IfModule>
<IfModule mod_expires.c>
<FilesMatch "\.(ico|gif|jpg|JPG|jpeg|png|PNG|swf|css|js|html?|xml|txt)$">
ExpiresActive On
ExpiresDefault "access plus 1 month"
</FilesMatch>
</IfModule>
#test write\n";
fwrite($fh, $Data);
fclose($fh); 
?>
how do i include the code in the $Data string bit?
 
Old 08-16-2010, 08:29 PM   #2
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
You have quotes embedded in your string. Therefor PHP considers the string as terminated.

Code:
<FilesMatch "\.(ico|gif|jpg|JPG|jpeg|png|PNG|swf|css|js|html?|xml|txt)$">
You must escape every quote:
Code:
<FilesMatch \"\.(ico|gif|jpg|JPG|jpeg|png|PNG|swf|css|js|html?|xml|txt)$\">
I did not check them all.

jlinkels
 
Old 08-16-2010, 08:35 PM   #3
steve51184
Member
 
Registered: Dec 2006
Posts: 381

Original Poster
Rep: Reputation: 30
perfect thank you
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Does fwrite() write entire file on jffs2? bjj2282 Linux - Software 0 10-26-2007 10:03 AM
Slow file writing with 'fwrite' function in C-code... scho Programming 5 08-07-2006 12:42 AM
c++ append data to file blizunt7 Programming 3 07-04-2005 12:47 AM
inserting the data thru php in a text file suchi_s Programming 5 02-02-2005 03:28 AM
radius append/add data ethanchic Linux - Software 0 04-16-2003 02:05 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 02:20 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration