Actions

API17

Difference between revisions of "JFile::makeSafe"

From Joomla! Documentation

(Updated to r1448:247ba8d88526)
m (User contributed notes: added example)
Line 37: Line 37:
 
</span>
 
</span>
 
===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>
 +
 +
 
<CodeExamplesForm />
 
<CodeExamplesForm />
 
<dpl>
 
<dpl>

Revision as of 04:02, 1 July 2012

Replacement filing cabinet.png
This Namespace has been archived - Please Do Not Edit or Create Pages in this namespace. Pages contain information for a Joomla! version which is no longer supported. It exists only as a historical reference, will not be improved and its content may be incomplete.

Joomla 11.1 JFile::makeSafe

Description

Makes file name safe to use.

Description:JFile::makeSafe [Edit Descripton]

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 Joomla 11.1

See also

SeeAlso:JFile::makeSafe [Edit See Also]

User contributed notes

Example

                //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']);


<CodeExamplesForm />