Jump to content

Recommended Posts

Ok I don't know PHP, I just want to know if this file can create a HTML(text file) 

 

<?php

$fileName = $_POST['fName'].".html";

$fileText = $_POST['fText'];

$file=fopen($fileName,"a+");

fwrite($file,$fileText);

echo "&resu=Created ".$fileName;

?>

 

can you test and if possible fix it.

Link to comment
https://forums.phpfreaks.com/topic/110932-need-help-file-check/
Share on other sites

<?php

$fileName = $_POST['fName'].".html";

$fileText = $_POST['fText'];

$file=fopen($fileName,"w+");

fwrite($file,$fileText);

fclose($file)

echo "&resu=Created ".$fileName;

?>

 

I don't know PHP, I'm trying to use PHP to write files with actionscript 3.0 since actionscript 3.0 can't write files.  Can you tell If it's oK

Link to comment
https://forums.phpfreaks.com/topic/110932-need-help-file-check/#findComment-569104
Share on other sites

I saw no problem except the missing semicolon after fclose() line, as ober said. The only other thing could happen is the variable $fileName is blank or something. Try to echo it to check whether there is a valid name available in that variable.

You'll want to change "a+" to "w+" and make sure you use fclose($file); at the end.

 

http://us2.php.net/fwrite

Worng. 'a+' is not a problem. from php manual

'a+' = Open for reading and writing; place the file pointer at the end of the file. If the file does not exist, attempt to create it.  

 

Link to comment
https://forums.phpfreaks.com/topic/110932-need-help-file-check/#findComment-569872
Share on other sites

Hey, you tried it with ending semicolon(;) placed after fclose() line? I try your code and it works man!!

<?php
$fileName = $_POST['fName'].".html";
$fileText = $_POST['fText'];
$file=fopen($fileName,"w+");
fwrite($file,$fileText);
fclose($file);
echo "&resu=Created ".$fileName;
?>

 

As I said, the other possibilities is, may be somehow you dont get the POST variable write. To ensure that, print those two post variables

<?php
$fileName = $_POST['fName'].".html";
$fileText = $_POST['fText'];

echo "this is file name : ".$fileName;   //check whether these two lines print what you wish
echo "this is file text : ".$fileText;      //check whether these two lines print what you wish

$file=fopen($fileName,"w+");
fwrite($file,$fileText);
fclose($file)
echo "&resu=Created ".$fileName;
?>

 

and remember, in this case, file will be created in the same folder where your php file is.

Link to comment
https://forums.phpfreaks.com/topic/110932-need-help-file-check/#findComment-569945
Share on other sites

ok .. then sorry .. but you do check this two line, right?

echo "this is file name : ".$fileName;   //check whether these two lines print what you wish
echo "this is file text : ".$fileText;      //check whether these two lines print what you wish
[code]

and get the $fileName printed?

[/code]

Link to comment
https://forums.phpfreaks.com/topic/110932-need-help-file-check/#findComment-569956
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.