Hi guys,
I hope someone can help me with this. I have been stumped all morning as to why it's not working.
I have 2 gallery's clients and applicants
the images in these gallery's are number sequentially
1_thumb.jpg
1_main.jpg
2_thumb.jpg
2_main.jpg
And so on....
When i want to delete any images from the clients gallery i use the script below
$filePath = '../media/models/'.$_POST['cl_id']."/";
$imgThumb = $_POST['imgThumb'];
$imgXLs = $_POST['imgMain'];
if(!unlink($filePath.$imgThumb)) {
$error = "Error deleting thumb nail from server.";
print $error;
exit;
}
if(!unlink($filePath.$imgXLs)) {
$error = "Error deleting large image from server.";
print $error;
exit;
}
if ($handleA = opendir($filePath)) {
$i=0;
while (false !== ($fileA = readdir($handleA))) {
if ($fileA != "." && $fileA != "..") {
if(substr_count($fileA, '_main.jpg')==1){
//
}else if(substr_count($fileA, 'spotlite.jpg')==1){
//
}else if(substr_count($fileA, 'Thumbs.db')==1){
//
}else{
$i++;
rename($filePath.$fileA, $filePath.$i."_thumb.jpg");
}
}
}
closedir($handleA);
}
if ($handleB = opendir($filePath)) {
$j=0;
while (false !== ($fileB = readdir($handleB))) {
if ($fileB != "." && $fileB != "..") {
if(substr_count($fileB, '_thumb.jpg')==1){
//
}else if(substr_count($fileB, 'spotlite.jpg')==1){
//
}else if(substr_count($fileB, 'Thumbs.db')==1){
//
}else{
$j++;
rename($filePath.$fileB, $filePath.$j."_main.jpg");
}
}
}
closedir($handleB);
}
print "&retval=1&";
Now this delete's the relevent image then rename's all the files keeping the sequential flow of numbers.
I use the same script to delete images from the applicants folder
$filePath = '../media/modelapps/'.$_POST['app_id']."/";
$imgThumb = $_POST['imgThumb'];
$imgXLs = $_POST['imgMain'];
if(!unlink($filePath.$imgThumb)) {
$error = "Error deleting thumb nail from server.";
print $error;
exit;
}
if(!unlink($filePath.$imgXLs)) {
$error = "Error deleting large image from server.";
print $error;
exit;
}
if ($handleA = opendir($filePath)) {
$i=0;
while (false !== ($fileA = readdir($handleA))) {
if ($fileA != "." && $fileA != "..") {
if(substr_count($fileA, '_main.jpg')==1){
//
}else if(substr_count($fileA, 'spotlite.jpg')==1){
//
}else if(substr_count($fileA, 'Thumbs.db')==1){
//
}else{
$i++;
rename($filePath.$fileA, $filePath.$i."_thumb.jpg");
}
}
}
closedir($handleA);
}
if ($handleB = opendir($filePath)) {
$j=0;
while (false !== ($fileB = readdir($handleB))) {
if ($fileB != "." && $fileB != "..") {
if(substr_count($fileB, '_thumb.jpg')==1){
//
}else if(substr_count($fileB, 'spotlite.jpg')==1){
//
}else if(substr_count($fileB, 'Thumbs.db')==1){
//
}else{
$j++;
rename($filePath.$fileB, $filePath.$j."_main.jpg");
}
}
}
closedir($handleB);
}
print "&retval=1&";
I get errors renaming files. file already exsists.
i have checked the folder permissions and both are as they should and for added measure i used unmask in the off chance there was a problem with the folder permissions.
Any????