473,811 Members | 2,038 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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='".$_SE SSION['NCI']."' AND
QuestionIndex IN (".join(",", $_SESSION['questions']).") ORDER BY
QuestionIndex";

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

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

}else {
echo "Couldn't change directory\n";
}
$fp = fopen('ptq'.$_S ESSION['username'].time().'.txt', 'w')
or die('Could not open the text file for writing');
while ($nt = mysql_fetch_arr ay($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 1642
"Ian Davies" <ia********@vir gin.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.ber keley.edu/>
Kimmo Laine <an************ *******@gmail.c om.NOSPAM.inval id>
Nov 6 '05 #2
That gives the following message

Warning: fopen(../htdocs/Downloads/ptqiandandav113 1304863.txt): failed to
open stream: No such file or directory in
e:\domains\i\id dsoftware.co.uk \user\htdocs\Qu estionDB\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.c om.NOSPAM.inval id> wrote in
message news:dk******** **@phys-news1.kolumbus. fi...
"Ian Davies" <ia********@vir gin.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.ber keley.edu/>
Kimmo Laine <an************ *******@gmail.c om.NOSPAM.inval id>

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

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

Warning: fopen(../htdocs/Downloads/ptqiandandav113 1304863.txt): failed to
open stream: No such file or directory in
e:\domains\i\id dsoftware.co.uk \user\htdocs\Qu estionDB\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.c om.NOSPAM.inval id> wrote in
message news:dk******** **@phys-news1.kolumbus. fi...
"Ian Davies" <ia********@vir gin.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.ber keley.edu/>
Kimmo Laine <an************ *******@gmail.c om.NOSPAM.inval id>


Nov 6 '05 #4

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

Similar topics

10
4629
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
2086
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 writing new files to the created directory results in an access denied error. Thanks to a script by Keith Brown, I was able to determine who my application was running as: > ====================================================== >
2
2615
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 FileUpload control SaveAs method to upload and save the file. This all works fine when the virtual directory points to a local drive on the ASP.NET server. However, when pointing to a remote drive (which is what my client wants to do), I get...
3
1320
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> <jobtime>200607120616</jobtime> <Directory> <dirname>C:\Program Files\Acorden SourceXT</dirname> <file>
3
2178
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. But when I read the file the file seems to be incomplete. Further inspecting it has seemed to have stopped writing to the file at a certain point. Something in my code? a bug? System: Linux 2.4.31 (Slackware), Python 2.5c1 Any help is greatly...
2
1544
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 (A) ---- It uses output buffering. Modules files are included before <html>. The whole middle output (e.g. article with comment, registration form) is stored in RAM (or SWAP :D) and prepared for putting it into the main layout inside <body>....
6
38166
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 want to create the file in that directory. So, i would like to know: 1.) How to create a directory in c ? (in linux and windows) 2.) How to create a file in the directory which has been created ? (in linux and windows) I tried but i failed....
1
2560
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 write the output of each file read in the directory into a separate file. # whitespace by comma in every line import fileinput, string, sys, os from os.path import join if len(sys.argv) != 2: print "Enter: python %s input_directory" %...
0
9605
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10648
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10135
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9205
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7670
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5554
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4339
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3867
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3018
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.