Skip to content

Instantly share code, notes, and snippets.

@abacha
Created April 3, 2010 00:57
Show Gist options
  • Save abacha/353937 to your computer and use it in GitHub Desktop.
Save abacha/353937 to your computer and use it in GitHub Desktop.
<?
function beforeSave() {
if (isset($_SESSION["Config"]["userAgent"]))
$this->data["BookFiles"] = $this->uploadFiles();
return true;
}
function uploadFiles() {
$dir = "uploadify/files/".$_SESSION["Config"]["userAgent"]."/";
if (is_dir($dir)) {
$handle = opendir($dir);
while (false !== ($file = readdir($handle)))
if ($file != "." && $file != "..") {
$old_name = $file;
$cont = 2;
while (file_exists("files/".$file)) {
$file = pathinfo($file);
$file = $file["filename"]."-".$cont.".".$file["extension"];
$cont++;
}
rename($dir.$old_name, "files/".$file);
$files[] = array("name" => $file);
chmod("files/".$file, 0755);
}
closedir($handle);
rmdir($dir);
return $files;
}
else return false;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment