Log in
پنج شنبه,۰۷ مرداد ماه ۱۳۸۹مطابق با
١٦ شعبان ۱۴۳۱هجرى قمرى

PHP File/Dir Operations
1- Opening and Reading a File Line by Line
a- read Line by Line
<html><body>
<?php
$filename = “test.txt”;
$fp = fopen( $filename, “r” ) or die(“Couldn’t open $filename”);
while ( ! feof( $fp ) ) {
$line = fgets( $fp, 1024 );
print “$line<br>”;
}
?>
</body></html>
a- read with fread()
<html><body>
<?php
$filename = ”test.txt”;
$fp = fopen( $filename, ”r” ) or die(“Couldn’t open $filename”);
while ( ! feof( $fp ) ) {
$chunk = fread( $fp, 16 );
print ”$chunk<br>”;
}
?>
</body></html>
c- read by char
<html><body>
<?php
$filename = ”test.txt”;
$fp = fopen( $filename, ”r” ) or die(“Couldn’t open $filename”);
while ( ! feof( $fp ) ){
$char = fgetc( $fp );
print ”$char<BR>”;
}
?></html></body>
2- Upload: path, file name, size and type
<html>
<?php
$file_dir = “.”; $file_url = “.”;
if ( isset( $fupload ) ){
print “path: $fupload<br>\n”;
print “name: $fupload_name<br>\n”;
print “size: $fupload_size bytes<br>\n”;
print “type: $fupload_type<p>\n\n”;
if ( $fupload_type == “image/gif” ){
copy ( $fupload, “$file_dir/$fupload_name”) or
die (“Couldn’t copy”);
print “<img
src=\”$file_url/$fupload_name\”><p>\n\n”;
}
}
?>
<body>
<form enctype=”multipart/form-data” action=”<?php print
$PHP_SELF?>” method=”POST”>
<input type=”hidden” name=”MAX_FILE_SIZE”
value=”51200″>
<input type=”file” name=”fupload”>
<input type=”submit” value=”Send file!”>
</form>
</body></html>
Post your comment
Archives:
- Mercurial & hg view
- jPortal wordpress theme
- WordPress Careers plugin
- Check For Email pattern
- WordPress ODLinks Plugin
- WordPress Classifieds Plugin
- Clean up the Ubuntu
- Persian philosophs and sciences
Subpages
- Partition and Format
- Application in chroot
- Realplayer and IE
- SSL & Serverzertifikat
- Debian Package
- Solaris Package
- Linux commands
- Web service
- PHP
- PERL
Categories:
Root Category
Links
- (IE)HTML - اديتور به فارسي و لاتين
- Online Graphic Plotter
- Online scientific calculator
- تقويم ساليانه
- تبديل کُدهای رايج
- تبدیل تاریخ شمسی به میلادی
- فارسی نويس
- تبديل خط فينگليش به فارسى
Local times
- CEST: 2010-07-29 20:06
- EDT: 2010-07-29 14:06
- IRDT: 2010-07-29 22:36
- KST: 2010-07-30 03:06
- PDT: 2010-07-29 11:06





