Jump to content

Need help file check


ia.studio

Recommended Posts

<?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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.