|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
how to create a file..?
Hi,
how do i write to create a new file(html extension)? thanks in advance adam |
|
#2
|
||||
|
||||
|
hi startrader,
its simple to create a new file. first decide where u want to create file. you can try something like Code:
$path = 'c:/temp'; $name = 'first.html'; $filename = $path.$filename; fopen(FILE,">$filename"); this code will give u file handle named FILE and you can use it to write in to that file and other stuff. simple enough ?? right ? best of luck, jd p.s: specifyin path is not compulsory but in that case file will be created in current directory of script.
__________________
_____________________________ d.k.jariwala (JD) ~ simple thought, simple act ~ I blog @ http://jdk.phpkid.org |
|
#3
|
|||
|
|||
|
hmmm i feel like an idiot.....
im trying to create some files on my server,but it doesnt create anyone? Weird... I tested $name = 'first.html'; open(FILE,">$name"); close(FILE); and $name = 'first.html'; fopen(FILE,">$name"); close(FILE); but it didnt create any file ? |
|
#4
|
|||
|
|||
|
now its working , i didnt chmod the directory before (777) what a newbie iam
![]() |
|
#5
|
||||
|
||||
|
hi star,
fine..so u found whats goin wrong hard way.. better method is to use Perl only to report u the probs. see whenever u have critcal functions like fopen or connecting to database use error handling. you can do this. Code:
fopen(FILE,">abc.html") || error_handle("Can not open file. Reason : $!" );
## error handle fucntion.
sub error_handle
{
$error = $_[0];
print "There is error. $error";
exit;
}
here || is or operator and if fopen fails then error_handle would be called. [ i hope u have some idea about || operator ] here trick is $! . it is a perl langauge variable which holds info about what error occured last. so that u know where u have prob. right ?? so try to use this, it has helped me a great deal in debugging, best of luck to u too, jd |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Perl Programming > how to create a file..? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|