Ticket #414 (closed Bug: fixed)
Form_Upload in Forge throws "Undefined variable: filepath"
| Reported by: | cufo | Owned by: | Shadowhand |
|---|---|---|---|
| Priority: | trivial | Milestone: | 2.1.2 |
| Component: | Modules:Forge | Version: | SVN HEAD |
| Keywords: | forge upload undefined variable | Cc: |
Description
public function validate()
{
// The upload directory must always be set
empty($this->directory) and $this->directory();
// By default, there is no uploaded file
$filename = '';
if ($status = parent::validate() AND $this->upload['error'] === UPLOAD_ERR_OK)
{
// Set the filename to the original name
$filename = $this->upload['name'];
if (Config::item('upload.remove_spaces'))
{
// Remove spaces, due to global upload configuration
$filename = preg_replace('/\s+/', '_', $this->data['value']);
}
if (file_exists($filepath = $this->directory.$filename))
{
if ($this->filename !== TRUE OR ! is_writable($filepath))
{
// Prefix the file so that the filename is unique
$filepath = $this->directory.'uploadfile-'.uniqid(time()).'-'.$this->upload['name'];
}
}
// Move the uploaded file to the upload directory
move_uploaded_file($this->upload['tmp_name'], $filepath);
}
if ( ! empty($_POST[$this->data['name']]))
{
// Reset the POST value to the new filename
$this->data['value'] = $_POST[$this->data['name']] = $filepath;
}
return $status;
}
Change History
Note: See
TracTickets for help on using
tickets.
