473,387 Members | 1,520 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,387 software developers and data experts.

writing files to a choosen directory


Hello
I have the following code which changes directory, creates a file and then
writes rows to it. It works fine except the file is created in the folder
the php script is in instead of the download directory specified in the
scrip. Can anyone see where I have gone wrong
Also I want to show the question Index and Question on screen as a list.
Ive put

echo $nt['QuestionIndex'], $nt['Question'];

here <<<<<<<<<<<<<<<< in the script
but it doesnt work, any ideas?

Ian

******************************
$query= "SELECT * FROM Questions WHERE NCIndex='".$_SESSION['NCI']."' AND
QuestionIndex IN (".join(",", $_SESSION['questions']).") ORDER BY
QuestionIndex";

$rt=mysql_query($query)
or die(mysql_error());
echo mysql_error();

if (ftp_chdir($conn_id, "../htdocs/Downloads")) {
echo "Current directory is now: " . ftp_pwd($conn_id) . "\n";

}else {
echo "Couldn't change directory\n";
}
$fp = fopen('ptq'.$_SESSION['username'].time().'.txt', 'w')
or die('Could not open the text file for writing');
while ($nt = mysql_fetch_array($rt, MYSQL_NUM)){

$line = "INSERT INTO tQuestions VALUES ('', '" .
implode("', '", $nt) .
"');\r\n";
fwrite($fp, $line);
echo $nt['QuestionIndex'], $nt['Question']; <<<<<<<<<<<<<<<
}
fclose($fp);

***************************
Nov 6 '05 #1
3 1624
"Ian Davies" <ia********@virgin.net> kirjoitti
viestissä:Lg*****************@newsfe6-win.ntli.net...

Hello
I have the following code which changes directory, creates a file and then
writes rows to it. It works fine except the file is created in the folder
the php script is in instead of the download directory specified in the
scrip. Can anyone see where I have gone wrong
Also I want to show the question Index and Question on screen as a list.
Ive put

Your code opens an ftp connection, but it doesn't write to it. it does
change the directory in the ftp-connection, but that is irrelevant if you
are writing to a local file. Just change the code to $fp =
fopen('../htdocs/Downloads/ptq'.$_SESSION['username'].time().'.txt', 'w'));
and remove the ftp-stuff, and you're good to go.

--
SETI @ Home - Donate your cpu's idle time to science.
Further reading at <http://setiweb.ssl.berkeley.edu/>
Kimmo Laine <an*******************@gmail.com.NOSPAM.invalid>
Nov 6 '05 #2
That gives the following message

Warning: fopen(../htdocs/Downloads/ptqiandandav1131304863.txt): failed to
open stream: No such file or directory in
e:\domains\i\iddsoftware.co.uk\user\htdocs\Questio nDB\notify.php on line 43
Could not open the text file for writing

but the directory does exist

Is the file local if its in a directory on my hosts server ?

"Kimmo Laine" <an*******************@gmail.com.NOSPAM.invalid> wrote in
message news:dk**********@phys-news1.kolumbus.fi...
"Ian Davies" <ia********@virgin.net> kirjoitti
viestissä:Lg*****************@newsfe6-win.ntli.net...

Hello
I have the following code which changes directory, creates a file and then writes rows to it. It works fine except the file is created in the folder the php script is in instead of the download directory specified in the
scrip. Can anyone see where I have gone wrong
Also I want to show the question Index and Question on screen as a list.
Ive put

Your code opens an ftp connection, but it doesn't write to it. it does
change the directory in the ftp-connection, but that is irrelevant if you
are writing to a local file. Just change the code to $fp =
fopen('../htdocs/Downloads/ptq'.$_SESSION['username'].time().'.txt',

'w')); and remove the ftp-stuff, and you're good to go.

--
SETI @ Home - Donate your cpu's idle time to science.
Further reading at <http://setiweb.ssl.berkeley.edu/>
Kimmo Laine <an*******************@gmail.com.NOSPAM.invalid>

Nov 6 '05 #3
OK
I done it
I didnt need the htdocs bit in the path
Ian

"Ian Davies" <ia********@virgin.net> wrote in message
news:RN******************@newsfe6-win.ntli.net...
That gives the following message

Warning: fopen(../htdocs/Downloads/ptqiandandav1131304863.txt): failed to
open stream: No such file or directory in
e:\domains\i\iddsoftware.co.uk\user\htdocs\Questio nDB\notify.php on line 43 Could not open the text file for writing

but the directory does exist

Is the file local if its in a directory on my hosts server ?

"Kimmo Laine" <an*******************@gmail.com.NOSPAM.invalid> wrote in
message news:dk**********@phys-news1.kolumbus.fi...
"Ian Davies" <ia********@virgin.net> kirjoitti
viestissä:Lg*****************@newsfe6-win.ntli.net...

Hello
I have the following code which changes directory, creates a file and then writes rows to it. It works fine except the file is created in the folder the php script is in instead of the download directory specified in the scrip. Can anyone see where I have gone wrong
Also I want to show the question Index and Question on screen as a list. Ive put

Your code opens an ftp connection, but it doesn't write to it. it does
change the directory in the ftp-connection, but that is irrelevant if you are writing to a local file. Just change the code to $fp =
fopen('../htdocs/Downloads/ptq'.$_SESSION['username'].time().'.txt',

'w'));
and remove the ftp-stuff, and you're good to go.

--
SETI @ Home - Donate your cpu's idle time to science.
Further reading at <http://setiweb.ssl.berkeley.edu/>
Kimmo Laine <an*******************@gmail.com.NOSPAM.invalid>


Nov 6 '05 #4

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

Similar topics

10
by: Neil Trigger | last post by:
Is there a way of creating a seperate text file on a server every time a form is sent? -- ¿ Trigger ? http://www.magic2k.com/ http://www.oddmap.co.uk
6
by: darrel | last post by:
I'm struggling with an odd permissions problem I have with one of my functions. It takes a file, writes a directory, and then uploads some files to it. This works. Once. Any subsequent attempt and...
2
by: BLetts | last post by:
I have an ASP.NET app that must allow users to upload files. The files are stored in a virtual directory. I use Server.MapPath to map from the virtual directory name to a physical path, then the...
3
by: Moqtar | last post by:
I am using python to walk a directory and write the filename in an xml document of type <?xml version="1.0" encoding="ISO-8859-1"?> <job> <jobname>Test</jobname>...
3
by: Adonis Vargas | last post by:
I am writing a program that walks a directory full of mp3s reads their ID3 data (using Mutagen), this part works perfectly. The problem is I write these tags to a CSV file through the CSV module....
2
by: webcm123 | last post by:
I'm making some changes in files structure in my CMS. I will use more templates for modules. However, the topic of <titleand other ... came back when i was thinking about it. ---- Pre-generating...
6
by: plomon | last post by:
whenever, i try to open a file for writing using fopen("xyz.txt", "w"), i am able to create the file only in default C:\ drive. i want to create a directory in the process of running the c code and...
1
by: lqnt1981 | last post by:
Following is the code in python that opens all files under a directories and puts a comma in place of whitespace, I can see the output on the command line, but I am not sure what to do in order to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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.