|
-
Aug 19th, 2002, 11:16 AM
#1
Thread Starter
Addicted Member
create a file
if a file doesnt exists, how do I create on in php? simple one but I never really worked with files before.
-
Aug 19th, 2002, 11:21 AM
#2
Fanatic Member
well if your writing to a file, and it does not exist it will create it.
-
Aug 19th, 2002, 11:46 AM
#3
Thread Starter
Addicted Member
ok, this goes with my other question. I'm creating a file upload for where someone submits their zip file and I upload it to the file server and I want to add some kind of bar so they know how much is uploaded (I know thats going to be a pain). But for right now I'm trying to just throw text into a file on the ftp server... here's what my code looks like..
<?php
$file = fopen ("ftp://username [email protected]/uploads/text", "w");
if (!$file) {
echo "<p>Unable to open remote file for writing.\n";
exit;
}
/* Write the data here. */
fputs ($file, "This is my test" . "\n");
echo("File Created?");
fclose ($file);
?>
now, when are no files in that directory it does nothing. When I create a text document with the same name text.txt it creates the text file with no extension. when the text file with no extension exists, it gives me an error that it cant over write existing file...
-
Aug 19th, 2002, 12:19 PM
#4
Fanatic Member
You have to give the file you are writing to a name, even if it does not exist yet
$file = fopen ("ftp://[email protected]/uploads/text/sometextfile.txt", "w");
-
Aug 19th, 2002, 12:49 PM
#5
Thread Starter
Addicted Member
cool, I got that working. Now its typing a line of information into the file. But the new problem is that its looking to write to the file, the information from the remote user file and I keep getting this...
Warning: file("C:\Programming\test.txt") - No such file or directory in /home/sites/home/web/member/uploadthefile.php on line 16
Any ideas?
-
Aug 19th, 2002, 12:58 PM
#6
Fanatic Member
with fopen use 'a' instead of 'w'
-
Aug 20th, 2002, 07:11 AM
#7
Thread Starter
Addicted Member
alright, this thing has me tapping out... I get to a point where it works, then it doesnt work. here's my code.
<?
echo($thisfile); //just to see the tmp filename
$fd = fopen ($thisfile, "r"); //$thisfile is from a file input type on the previous page
while (!feof ($fd)) {
$buffer = $buffer.fgets($fd, 4096);
}
fclose ($fd);
mail("[email protected]", "Subject", $buffer, "FROM:[email protected]");
//mail myself the $buffer string to make sure its got stuff in it (which is always does)
$XXfileX = fopen ("ftp://username [email protected]/uploads/test.txtxt", "a+");
fputs($XXfileX, $buffer."\n");
fclose($XXfileX);
?>
The thing is, it works sometimes and not others. Like if I post my file and refresh this php page around 3 times, it'll show up on the ftpserver. But not the first or second time. There seems to be no consistancy to when it goes through and I cant figure it out. Can anybody help?
-
Aug 20th, 2002, 09:17 AM
#8
Lively Member
If filename begins with "ftp://" (not case sensitive), an ftp connection to the specified server is opened and a pointer to the requested file is returned. If the server does not support passive mode ftp, this will fail. You can open files for either reading or writing via ftp (but not both simultaneously).
are you sure it supports passive mode?
Just Imagine what you can do with the power of php.
257 Tutorials and counting.
529 Snippets and growing.
Add yours today @
SnippetLibrary.com
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|