
12-12-03, 01:01 AM
|
|
Newbie Coder
|
|
Join Date: Dec 2003
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
PHP Upload Form Help
In the past i have created quite a few PHP based FTP programs, whereby the user would get the file from their computer by browsing, and upload it to the server. My friend asked me to create a program whereby they would enter text into an input box/text area, and then upload, and it would create a file on their server, just like the FTP program, but without having the file on their computer. Their host just supports PHP, not MySQL, so i was wondering if it's possible (although i pressume it is, seeing that my FTP program was entirely based on PHP, without MySQL), to do this? If so, could someone give me a little help on it please, thanks 
|

12-12-03, 01:19 AM
|
 |
Junior Code Guru
|
|
Join Date: Dec 2003
Location: Vancouver, BC, Canada
Posts: 550
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi there,
So basically your friend wants to create a file and its contents on-the-fly via textarea/box, correct?
If so, you can use fopen($filename, 'w').
I believe fopen() with access mode 'w', 'w+', 'a', or 'a+' will create the file with file name of $filename if it does not already exist. You can first create it and then do whatever you want with the file and user input.
Hope this helps.
__________________
Blavv =|
|

12-12-03, 04:57 AM
|
|
Newbie Coder
|
|
Join Date: Dec 2003
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I'm using the following code at the moment, but it's not displaying the file at all, but i know the path is correct. The textarea box is just blank, and i have CHMODed the file.php to 666. Any help would be very useful...
The save.php file is:
|

12-12-03, 06:02 AM
|
 |
Junior Code Guru
|
|
Join Date: Dec 2003
Location: Vancouver, BC, Canada
Posts: 550
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi there.
I just literally copy & pasted your code except for the first line where you assign the path to $file and ran the scripts on my server. Other than getting fclose() wrong param error (you've forgotten $fs for fclose() in save.php), it seems to work just fine for me.
Are you getting any error message? Have you tried outputing into non-textarea? Did you check if your input has been saved onto the file that you specified properly?
Sorry I can't say further than this given the situation...
__________________
Blavv =|
|

12-12-03, 06:32 AM
|
|
Newbie Coder
|
|
Join Date: Dec 2003
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Well i've got it to semi-work by changing the a+ in save.php to w and by changing the top to:
I'm just wondering if that's safe, and will it work, becuase when i click submit it says:
Quote:
Warning: fopen("","w") - Inappropriate ioctl for device in /home/sites/site10/web/save.php on line 2
error when opening the file
|
Could you possibly change the code for that to make it work, by changing save.php, or does the main file has to be changed? What needs to be altered? Thanks 
Last edited by tsb; 12-12-03 at 07:14 AM.
|

12-12-03, 10:14 AM
|
|
Newbie Coder
|
|
Join Date: Dec 2003
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Gah, i'm just really confused, any help is very needed...
I know something must be wrong with the save.php file, so if anyone could please show me what i'd be grateful...
|

12-12-03, 03:40 PM
|
 |
Junior Code Guru
|
|
Join Date: Dec 2003
Location: Vancouver, BC, Canada
Posts: 550
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi there, my again =)
Just to let you know, edit mode of "w" is write-only and the moment you open the file with this param, all the file contents that was there will be truncated. Is that what you want?
Re remote file fopen, read this excellent doc from PHPBuilder: http://www.phpbuilder.com/manual2/ma...mote-files.php
It looks like there's no filename param passed to fopen().
Good luck!
__________________
Blavv =|
|

12-12-03, 06:18 PM
|
|
Newbie Coder
|
|
Join Date: Dec 2003
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi
With w will it basically overwrite the file then? That's what i want, and what someone told me it would do...
All i've got at the moment in save.php is:
Can you pssibly just change what parts need to be fixed, and explain why it still comes up with the same old error, thanks. 
|

12-12-03, 08:55 PM
|
 |
Junior Code Guru
|
|
Join Date: Dec 2003
Location: Vancouver, BC, Canada
Posts: 550
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi, it's me again.
Quote:
|
Originally Posted by tsb
Hi
With w will it basically overwrite the file then? That's what i want, and what someone told me it would do...
All i've got at the moment in save.php is:
Can you pssibly just change what parts need to be fixed, and explain why it still comes up with the same old error, thanks. 
|
Two things:
1) rewrite "fclose()" as "fclose($fs)" - you need a parameter (file handler) to close.
2) If you open the file with edit mode "w" in the first file (not save.php), try using "r" instead.
Other than this, it works fine on my server locally or remotely.
For debug reason you might want to add echo $_POST["contents"]; before you close the file in save.php. See if what you wrote was really written down.
Hope this helps.
__________________
Blavv =|
|

12-12-03, 10:15 PM
|
|
Newbie Coder
|
|
Join Date: Dec 2003
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I did that, and the save.php is now:
But it still comes up with this error:
It says fopen("","w"), so is it not getting the file as such that i'm trying to edit? The code above is the entire save.php file, so am i overlooking something? Thanks 
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|