Markie
Posts: 251
|
| Posted: 01/10/2009, 8:01 AM |
|
I have a Before Build Delete code but unfortunately I can't get this to work:
$user= $albums->username->GetValue();
$gallery = $albums->gallery->GetValue();
$dirname="uploadedfiles/$user/$gallery/";
function delete_directory($dirname) {
if (is_dir($dirname))
$dir_handle = opendir($dirname);
if (!$dir_handle)
return false;
while($file = readdir($dir_handle)) {
if ($file != "." && $file != "..") {
if (!is_dir($dirname."/".$file))
unlink($dirname."/".$file);
else
delete_directory($dirname.'/'.$file);
}
}
closedir($dir_handle);
rmdir($dirname);
return true;
}
No browser errors, but the directory and files still exists on my server
_________________
The Netherlands, GMT+1
Tools: CCS 5.1, Windows 7, Navicat, Ultraedit
Local server: XAMPP with Apache, php and MySQL
Webserver: Windows 2008 IIS 7, php and MySQL |
 |
 |
Gena
Posts: 591
|
| Posted: 01/10/2009, 9:03 AM |
|
Where you call your function delete_directory () ?? I see just function declaration...
you need to put something like
$user= $albums->username->GetValue();
$gallery = $albums->gallery->GetValue();
$dirname="uploadedfiles/$user/$gallery/";
$a = delete_directory($dirname);
........
_________________
Gena |
 |
 |
Markie
Posts: 251
|
| Posted: 01/10/2009, 10:23 AM |
|
Hi Gena, unfortunately adding this $a = etc. to my code has this browser error as a result:
Fatal error: Call to undefined function delete_directory() in etc. etc.
_________________
The Netherlands, GMT+1
Tools: CCS 5.1, Windows 7, Navicat, Ultraedit
Local server: XAMPP with Apache, php and MySQL
Webserver: Windows 2008 IIS 7, php and MySQL |
 |
 |
Gena
Posts: 591
|
| Posted: 01/10/2009, 10:39 AM |
|
but do you have
function delete_directory($dirname) {
...
}
in your code? Put (move) this function somewhere at the end of *s.php file
_________________
Gena |
 |
 |
Markie
Posts: 251
|
| Posted: 01/10/2009, 10:46 AM |
|
Yes, I have. My code at the moment is:
$user= $albums->username->GetValue();
$gallery = $albums->gallery->GetValue();
$dirname="uploadedfiles/$user/$gallery/";
$a = delete_directory($dirname);
function delete_directory($dirname) {
if (is_dir($dirname))
$dir_handle = opendir($dirname);
if (!$dir_handle)
return false;
while($file = readdir($dir_handle)) {
if ($file != "." && $file != "..") {
if (!is_dir($dirname."/".$file))
unlink($dirname."/".$file);
else
delete_directory($dirname.'/'.$file);
}
}
closedir($dir_handle);
rmdir($dirname);
return true;
}
_________________
The Netherlands, GMT+1
Tools: CCS 5.1, Windows 7, Navicat, Ultraedit
Local server: XAMPP with Apache, php and MySQL
Webserver: Windows 2008 IIS 7, php and MySQL |
 |
 |
Gena
Posts: 591
|
| Posted: 01/10/2009, 11:00 AM |
|
ok
I see 2 ways.
If you want to use and declare your function as now - just move function delete_directory($dirname) {
...
}
before (above) your code
$user= $albums->username->GetValue();
...
OR as I wrote before, move it at the end of php file...
_________________
Gena |
 |
 |
Gena
Posts: 591
|
| Posted: 01/10/2009, 11:15 AM |
|
and don't forget to Publish....
_________________
Gena |
 |
 |
Markie
Posts: 251
|
| Posted: 01/10/2009, 11:17 AM |
|
Thanks Gena, now it works !
_________________
The Netherlands, GMT+1
Tools: CCS 5.1, Windows 7, Navicat, Ultraedit
Local server: XAMPP with Apache, php and MySQL
Webserver: Windows 2008 IIS 7, php and MySQL |
 |
 |
|