Difference between revisions of "JFile::makeSafe"
From Joomla! Documentation
(Updated to r1448:247ba8d88526) |
m (preparing for archive only) |
||
(5 intermediate revisions by 2 users not shown) | |||
Line 4: | Line 4: | ||
Makes file name safe to use. | Makes file name safe to use. | ||
− | + | ||
− | + | ||
− | |||
− | |||
<source lang="php"> | <source lang="php"> | ||
public static function makeSafe ($file) | public static function makeSafe ($file) | ||
Line 29: | Line 27: | ||
===See also=== | ===See also=== | ||
* {{JVer|11.1}} '''JFile::makeSafe source code''' on [[jplatform:filesystem/file.php#cl-52|BitBucket]] | * {{JVer|11.1}} '''JFile::makeSafe source code''' on [[jplatform:filesystem/file.php#cl-52|BitBucket]] | ||
− | * {{JVer|11.1}} Class [[JFile | + | * {{JVer|11.1}} Class [[API17:JFile|JFile]] |
− | * {{JVer|11.1}} Subpackage [[Subpackage_Filesystem | + | * {{JVer|11.1}} Subpackage [[API17:Subpackage_Filesystem|Filesystem]] |
− | * [[JFile::makeSafe|Other versions of JFile::makeSafe]] | + | * [[API17:JFile::makeSafe|Other versions of JFile::makeSafe]] |
− | + | ||
− | + | ||
− | |||
− | |||
===User contributed notes=== | ===User contributed notes=== | ||
− | < | + | ===Example=== |
+ | <source lang="php"> | ||
+ | //Retrieve file details from uploaded file, sent from upload form | ||
+ | $file = JRequest::getVar('upload_file', null, 'files', 'array'); | ||
+ | |||
+ | //Import filesystem libraries. Perhaps not necessary, but does not hurt | ||
+ | jimport('joomla.filesystem.file'); | ||
+ | |||
+ | //Clean up filename to get rid of strange characters like spaces etc | ||
+ | $filename = JFile::makeSafe($file['name']); | ||
+ | </source> | ||
+ | |||
+ | |||
+ | === Code Examples === | ||
<dpl> | <dpl> | ||
noresultsheader=\n | noresultsheader=\n | ||
category=JFile::makeSafe | category=JFile::makeSafe | ||
− | + | namespace=CodeExample | |
category=MethodExample | category=MethodExample | ||
include=* | include=* | ||
Line 47: | Line 56: | ||
format= ,,, | format= ,,, | ||
</dpl> | </dpl> | ||
− | <noinclude>[[Category: | + | <noinclude>[[Category:Platform 11.1]][[Category:Archived pages API17]]</noinclude> |
Latest revision as of 22:01, 24 March 2017
The "API17" namespace is an archived namespace. This page contains information for a Joomla! version which is no longer supported. It exists only as a historical reference, it will not be improved and its content may be incomplete and/or contain broken links.
JFile::makeSafe[edit]
Description[edit]
Makes file name safe to use.
public static function makeSafe ($file)
Parameter | Type | Default | Description |
---|---|---|---|
$file | string | The name of the file [not full path] |
- Returns string The sanitised string
- Defined on line 60 of libraries/joomla/filesystem/file.php
- Since
See also[edit]
- JFile::makeSafe source code on BitBucket
- Class JFile
- Subpackage Filesystem
- Other versions of JFile::makeSafe
User contributed notes[edit]
Example[edit]
//Retrieve file details from uploaded file, sent from upload form
$file = JRequest::getVar('upload_file', null, 'files', 'array');
//Import filesystem libraries. Perhaps not necessary, but does not hurt
jimport('joomla.filesystem.file');
//Clean up filename to get rid of strange characters like spaces etc
$filename = JFile::makeSafe($file['name']);
Code Examples[edit]