473,386 Members | 1,785 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

File Writing Issue

I am writing a file using PHP and all is great thus far:

$file_contents = "<?php \n".
"\$file_inc_news_id = '" .$id. "' \n" .
"include( \$_SERVER['DOCUMENT_ROOT'] . '/news/news_item.php' );
\n" .
"?>";
$filename = $_SERVER['DOCUMENT_ROOT'] . "/" .date('his'). ".php";
$fp = fopen($filename , "w"); //to write a new file
fwrite($fp , $file_contents );
fclose($fp);

However I want to add the facility for the file to be written into a
sub directory that may or may not exist - if the folder exists then it
works fine - if it doesn't then it throws an error.

Without having to write a section of code to check if the folder
exists, is there a way of forcing PHP to build any required folders for
me?

Dec 20 '05 #1
2 1093
If you want to check if the sub directoy exists and if not create it
then its only two lines of code:

if (!file_exists($dir))
mkdir($dir)

If you are using php 5 there is a recursive param added. Never tried it
myself: http://ie2.php.net/mkdir

Dec 20 '05 #2
Thanks mate - that rocks my world!

Dec 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Sebastian Kemi | last post by:
How should a write a class to a file? Would this example work: object *myobject = 0; tfile.write(reinterpret_cast<char *>(myobject), sizeof(*object)); / sebek
40
by: Abby | last post by:
My .dat file will contain information like below. /////////// First 0x04 0x05 0x06 Second 0x07
6
by: Cable | last post by:
Hello, I am hoping that someone can answer a question or two regarding file access. I have created an app that reads an image from a file then displays it (using OpenGL). It works well using...
5
by: ZWeng | last post by:
I created a windows service using FileSystemWatcher to moniter a folder for file drops. The service uses FileStream and StreamReader to read and process the file. After it is done, the file is...
16
by: Eran.Yasso | last post by:
Hi, I have a mdb file shared in the LAN. I want to write app that verifies if it's open. If the file is not open, then my app can open the file. if the file is used, then the app won't open it....
9
by: Carl | last post by:
Hi Is it possible to find out if another process is using a paticular file (xml)? There does not seem to be anything useful in the File och Filestream class for this purpose. regards Carl
4
by: JimmyKoolPantz | last post by:
IDE: VB2005 FILE TYPE: DBF5 I appoligize if I am posting in the wrong group. Question: Is there a position in the dbf file structure that will allow me to delete a field, such as, the way the...
3
by: evenrik | last post by:
An a redhat box I have root, apache and other normal users run code that uses the logging module to write to the same log file. Since umasks are set to 2 or 022 this gets permission errors. I...
12
by: glennanthonyb | last post by:
Hi The company I work for has finally woken up to data security on our field laptops. I'm writing something in C# that will allow remote deletion of sensitive data and I don't believe...
5
by: =?Utf-8?B?UVNJRGV2ZWxvcGVy?= | last post by:
I have a .Net web service that converts the MODCA files to tif or png file format. This web service runs on a 2003 server. This web service first copies the MODCA file to be converted to a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.