Hi guys,
I am trying to migrate a form that upload an image on the server.
The file to upload must be saved in one of two differents directory depending on whether the user is registered or not.
If the user isn't logged then the file must be saved in "custom_path"\guests directory.
If the user is registered and logged the file must be saved in "custom_path"\<username> directory.
I added on top of the form some PHP lines like that:
I tried to put {var:userdir} in the Upload Directory field but file isn't uploaded.
If I manually write the whole same url in Upload Directory the file is uploaded.
How should I do to solve this problem?
I am trying to migrate a form that upload an image on the server.
The file to upload must be saved in one of two differents directory depending on whether the user is registered or not.
If the user isn't logged then the file must be saved in "custom_path"\guests directory.
If the user is registered and logged the file must be saved in "custom_path"\<username> directory.
I added on top of the form some PHP lines like that:
<?php
$jid = JFactory::getUser()->id;
$jusername = JFactory::getUser()->username;
$directorypath = $_SERVER['DOCUMENT_ROOT'] . "/images/custompath/";
if($jid > 0) {
$directoryName = $jusername;
}
else {
$directoryName = "guests";
}
if(!is_dir($directorypath.$directoryName)){
mkdir($directorypath.$directoryName, 0755);
}
$fullPath = $directorypath . $directoryName."/";
$fullPathW = str_replace("/", "\\", $fullPath);
$this->set("userdir", $fullPathW);
?>
I tried to put {var:userdir} in the Upload Directory field but file isn't uploaded.
If I manually write the whole same url in Upload Directory the file is uploaded.
How should I do to solve this problem?