To print the file ,use print_r($_FILES) in php file.
For this set enctype="multipart/form-data" in form action.
<?php print_r($_FILES); ?>
First you have to upload the file and copy it to a location.
$file_extension = strtolower(substr(strrchr($filename,"."),1));
switch( $file_extension ) {
case "pdf": $ctype="Content-Type:application/pdf"; break;
case "exe": $ctype="Content-Type:application/octet-stream"; break;
case "zip": $ctype="Content-Type:application/zip"; break;
case "doc": $ctype="Content-Type:application/msword"; break;
case "xls": $ctype="Content-Type:application/vnd.ms-excel"; break;
case "ppt": $ctype="Content-Type:application/vnd.ms-powerpoint"; break;
case "gif": $ctype="Content-Type:image/gif"; break;
case "png": $ctype="Content-Type:image/png"; break;
case "jpeg":$ctype="Content-Type:image/jpeg"; break;
case "jpg": $ctype="Content-Type:image/jpg"; break;
case "mp3": $ctype="Content-Type:audio/mpeg"; break;
case "wav": $ctype="Content-Type:audio/x-wav"; break;
case "mpe": $ctype="Content-Type:video/mpeg"; break;
case "mov": $ctype="Content-Type:video/quicktime"; break;
case "avi": $ctype="Content-Type:video/x-msvideo"; break;
case "xml": $ctype="Content-Type:text/xml"; break;
case "css": $ctype="Content-Type:text/css"; break;
case "js": $ctype="Content-Type:application/javascript"; break;
case "csv":$ctype="Content-Type: application/csv";break;
case "txt": $ctype="Content-type: text/plain";break;
default: $ctype="Content-type:application/force-download";
}
<?php $file=$_FILES['files_name']['tmp_name']; $dest_file=$_FILES['files_name']['name']; define('ROOT',"/var/www/html/tutorials/PHP/images/"); move_uploaded_file($file,ROOT.$dest_file); ?>
<?php $fh = fopen('test.html', 'a'); fwrite($fh, 'Hello world!
'); fclose($fh); unlink('test.html'); ?>
<?php // Read and write for owner, nothing for everybody else chmod("/somedir/somefile", 0600); // Read and write for owner, read for everybody else chmod("/somedir/somefile", 0644); // Everything for owner, read and execute for others chmod("/somedir/somefile", 0755); // Everything for owner, read and execute for owner group chmod("/somedir/somefile", 0750); ?>
<?php $handle = fopen("/home/rasmus/file.txt", "r"); ?>
fread() reads up to length bytes from the file pointer referenced by handle. Reading stops when length bytes have been read, EOF (end of file) is reached.
<?php // get contents of a file into a string $filename = "/usr/local/something.txt"; $handle = fopen($filename, "r"); $contents = fread($handle, filesize($filename)); fclose($handle); ?>
writes the contents of string to the file stream pointed to by handle. If the length argument is given, writing will stop after length bytes have been written or the end of string is reached, whichever comes first. fwrite() returns the number of bytes written, or FALSE on error.
<?php $fp = fopen('data.txt', 'w'); fwrite($fp, '1'); fwrite($fp, '23'); fclose($fp); // the content of 'data.txt' is now 123 and not 23! ?>
<?php $handle = fopen("/tmp/inputfile.txt", "r"); while (!feof($handle)) { $buffer = fgets($handle, 4096); echo $buffer; } fclose($handle); ?>
<?php $handle = @fopen(ROOT."holidays.csv", "r"); if ($handle) { while (!feof($handle)) { $buffer = fgetcsv($handle, 4096); print_r($buffer); } fclose($handle); } ?>