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
Subpages
- Partition and Format
- Application in chroot
- Realplayer and IE
- SSL & Serverzertifikat
- Debian Package
- Solaris Package
- Linux commands
- Web service
- PHP
- PERL
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
- » حاج آقا سيد عباس دوستانى
- » Highlights of Iran's history
- » Korea Live TVs
- » Take a free course online.
- » Learning French
- » Hosting & Service Provider
- » LIVE-STREAM
- » Aktuelle Angebote
- » Spiele für Schulkinder
- » Persian philosophs and sciences
- » Schule Übungsblätter
- » ایستگاه قطار دورتموند
Categories:
Links
- (IE)HTML - اديتور به فارسي و لاتين
- Online Graphic Plotter
- Online scientific calculator
- تقويم ساليانه
- تبديل کُدهای رايج
- تبدیل تاریخ شمسی به میلادی
- فارسی نويس
- تبديل خط فينگليش به فارسى





