I know jQuery has a forum of its own but I have an account here and I know that there are people here with javascript experience. Anyway here is the problem. I am using jQuery sortable as an interface to sort images in a slideshow. As of now I have it so that when the page loads it will load a list with all of the images from a folder in it and you can drag and drop them and order them how you please. Now here is where I have problems.
I have a trash button on each item in the list and when you click it, it will remove that item from the list but I also need it to delete the picture that is stored locally. I am comfortable using php for that because I am more familiar with it so the problem is just passing the path to the appropriate picture to be deleted. Here is the code for the list (it scans the folder and then for each it creates a list item with the picture):
<ul id="gallery" class="gallery ui-helper-reset ui-helper-clearfix">
<?php
$folder = "slideshow1";
$files = scandir($folder);
$fullPath = explode("/","http://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}",-1);
$string = implode("/",$fullPath)."/".$folder."/";
foreach($files as $index => $value)
{
$pathinfo = pathinfo($value);
if ($pathinfo['extension'] == "jpg")
{
?>
<li class="ui-widget-content ui-corner-tr">
<h5 class="ui-widget-header"><?php echo $value ?></h5>
<?php echo "<img src=".$string.$value." alt=".$string.$value." width='96' height='72' //>" ?>
<a href="<?php echo $string.$value ?>" title="View larger image" class="ui-icon ui-icon-zoomin">View larger</a>
<a href="link/to/trash/script/when/we/have/js/off" title="Delete this image" class="ui-icon ui-icon-trash">Delete image</a>
</li>
<?php
}
}
?>
</ul>
So when you click on the trash icon this function is called passing the item to be deleted as the argument:
function deleteImage( $item )
{
$item.fadeOut(function() {});
}
So all of this code works properly I just need to add a part to the deleteImage function that deletes the image file.
Now, problem two. Each time the user moves an item in the list I would like to rename all of the image files to the new order. This can be done on the update event in the list. The images in my folder are named 001.jpg, 002.jpg 003.jpg etc. and that dictates the order. So when you load them into the sortable list that is the order they appear. When someone moves an item (for example they drag 001.jpg after 002.jpg) I need to rename the files to match the new order (002.jpg would become 001.jpg and vice versa). This can be done again in php but I need to be able to pass the old file path and the new index to php so I can rename it. This is the part I am stuck on so it relates to the first problem: getting properties of each element in a list. Any help would be fantastic
