|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
str_replace() -
Replace Text Within a String
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
The PHP str_replace() function replaces some characters with some other
characters in a string.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
<?php
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
echo str_replace("world", "Dolly", "Hello world!"); // outputs Hello Dolly!
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
?>
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| how to find the base name | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <?php $path = "/testweb/home.php"; //Show filenameecho basename($path) ."<br/>"; //Show filename, but cut off file extension for ".php" filesecho basename($path,".php"); ?> |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ouytput is home.php home |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
The first parameter in the HTTP context is either
inline (default value, indicating it can be displayed inside the Web page, or as the Web page) or attachment (indicating it should be downloaded; most browsers presenting a 'Save as' dialog, prefilled with the value of the filename parameters if present).Content-Disposition: inline Content-Disposition: attachment Content-Disposition: attachment; filename="filename.jpg" |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
how to write the code to download the file <?php
$f="resume.doc";
$file = ("myfolder/$f");
$filetype=filetype($file);
$filename=basename($file);
header ("Content-Type: ".$filetype);
header ("Content-Length: ".filesize($file));
header ("Content-Disposition: attachment; filename=".$filename);
readfile($file);
?>
Suppose You have a directory inside with collection of multiple related Files . Display all stored files using opendir( ) and readdir( ) function. Download those particular file on w
<?php
$f="resume.doc";
load teh file name to varaible
$file = ("myfolder/$f");
load the oath name to a variable
$filetype=filetype($file);
find the file type
$filename=basename($file);
get the path name
header ("Content-Type: ".$filetype);
tells to browser it is which file type
header ("Content-Length: ".filesize($file));
tells to browsetr whats the file size
header ("Content-Disposition: attachment; filename=".$filename);
tells to browser it is downloadable or display with in a web page
readfile($file);
?>
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
PHP Download File Example: Text File
1. <?php
2. $file_url = 'http://www.javatpoint.com/f.txt';
3. header('Content-Type: application/octet-stream');
4. header("Content-Transfer-Encoding: utf-8");
5. header("Content-disposition: attachment; filename=\"" . basename($file_url) . "\"");
6. readfile($file_url);
7. ?>
PHP Download File Example: Binary File
1. <?php
2. $file_url = 'http://www.myremoteserver.com/file.exe';
3. header('Content-Type: application/octet-stream');
4. header("Content-Transfer-Encoding: Binary");
5. header("Content-disposition: attachment; filename=\"" . basename($file_url) . "\"");
6. readfile($file_url);
7. ?>
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| isset |
| $_FILES['userfile']['name']; |
| concatenation |
| if elese |
| move_uploaded_file |
| !empty |
| type input |
| type submit input |
| enctype |
| $_FILES['userfile']['size']; |
| $_FILES['userfile']['type']; |
| $_FILES['userfile']['tmp_name']; |
| str_replace |
|
|||||||||||||
No comments:
Post a Comment