You are here: Re: [PHP] write to file question, rewritten « PHP « IT news, forums, messages
Re: [PHP] write to file question, rewritten

Posted by "Mark Cain" on 06/02/05 04:45

Here is a function I use to write data to a file (It is similar to PHP 5's
file_put_contents but works for those who don't have a PHP 5 installation:)

function file_put_contents($filename, $data, $file_append = false) {
$fp = fopen($filename, (!$file_append ? 'w+' : 'a+'));
if(!$fp) {
trigger_error('file_put_contents cannot write in file.', E_USER_ERROR);
return;
};
fputs($fp, $data);
fclose($fp);
};


in addition to using the above code, be sure that you are writing to a
folder in which you have write permissions.

Once the function is available to your code you can write your data in a
manner like this:


file_put_contents('/root/directory/pathtoyourfile/mydata.txt',$filecontent);


Mark Cain



----- Original Message -----
From: "mayo" <mayo@nycinteractive.com>
To: <php-general@lists.php.net>
Sent: Wednesday, June 01, 2005 7:01 PM
Subject: [PHP] write to file question, rewritten


> I'm trying to write the results of a mysql_fetch_array db query to a
> file and am unable to.
>
> I'm putting the results into a variable $fileContent and then using
> fwrite().
>
> I would have liked to do something like:
>
> $filecontent =
>
> .
>
>
> $result = mysql_query( "
>
> SELECT orderedItems.*, items.*
> FROM orderedItems, items
> WHERE
> orderedItems.orderID=$orderID[0] AND
> orderedItems.itemID=items.itemsID
>
> ");
>
> while($row = mysql_fetch_array( $result ))
> {
>
> $theItemID=$row["orderedItems.itemID"];
> $theItemPrice=$row["itemPrice"];
> $theItemQty=$row["itemQty"];
>
> $thisItemID= sprintf("% 6d",$theItemID);
> $thisItemPrice= sprintf("%7.2f",$theItemPrice);
> $thisItemQty= sprintf("% 7d",$theItemQty);
>
> $thisOrder .
>
> $thisItemID .
>
> $thisItemPrice .
>
> $thisItemQty .
> }
>
> "; // end of $filecontent
>
> but that doesn't work.
>
> Mayo
>
>
>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация