File write

This is a discussion on "File write" within the PHP Forum section. This forum, and the thread "File write are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Aug 3rd, 2007, 12:47
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,772
Blog Entries: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alexgeek
Unhappy File write

Hey again

I'm writing a script so that i can type anything i want into a textarea then choose the file name and the file extension and submit it, it should then save it in a directory below called "files". I'm having a few problems with it though :/
here it is:
PHP: Select all

$filecode $_POST['code'];
$file $_POST['file'];
$ext $_POST['ext'];

 
$fp fopen("files/".$file.".".$ext"a+");
   
fwrite($fp"<html>".$filecode."</html>");
   
echo (
"success"); 
i get the echo. But no file appears. I have all permissions turned on the directory. I don't see the problem :s
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote

  #2 (permalink)  
Old Aug 3rd, 2007, 13:07
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,772
Blog Entries: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alexgeek
Re: File write

ahh sorry. I should of used get not post
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #3 (permalink)  
Old Aug 3rd, 2007, 13:53
c010depunkk's Avatar
SuperMember

SuperMember
Join Date: Apr 2007
Location: Willich, Germany
Age: 20
Posts: 593
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to c010depunkk
Re: File write

Remember to check if the file was written and to close your file handle again:
PHP: Select all

$filecode $_POST['code'];
$file $_POST['file'];
$ext $_POST['ext'];
$fp fopen("files/".$file.".".$ext"a+");
if(
fwrite($fp"<html>".$filecode."</html>")!=false) {
    echo (
"success");
}
fclose($fp); 
That should do the trick.
Reply With Quote
Reply

Tags
edit, file, save, write

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] do you write quicker Hosting & Domains 8 Dec 12th, 2007 05:13
Creating a log file (text file) and an XML file using XSL kdelacruz Other Programming Languages 1 Nov 4th, 2006 21:12
better way to write this? jimz PHP Forum 4 May 9th, 2006 11:21


All times are GMT. The time now is 07:27.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43