Das Problem mit der Anzeige habe ich gelöst! So wie der Code oben ist, gehts jetzt!
Nun habe ich aber das nächste Problem!
Ich will unter meinen Bilder ein Delete Text. Dieser habe ich so eingefügt:
HTML-Code:
<?php
## Now create a correct number for your photo's
$vowels = array($id, "-", ".jpg", ".bmp", ".gif", ".png");
$imagenumber = str_replace($vowels, "", $image[$i]);
?>
<a href="index.php?option=com_test&task=deleteimg&image=<?php echo $imagenumber; ?>&cid=<?php echo $id; ?>" >
<?php echo JText::_( 'DELETE IMAGE' ); ?></a><br />
Meine Funktion im Model sieht so aus:
PHP-Code:
################################################################
## This function will delete the images ##
################################################################
function deleteimg(){
global $mainframe, $option;
$image = JRequest::getInt( 'image', 0 );
$cid = JRequest::getInt( 'cid', 0 );
if ($cid == 0){
$msg = JText::_( 'NO TEST SELECTED' );
$link = 'index.php?option=com_test&controller=dealers';
$mainframe->redirect($link, $msg);
}
if ($image == 0){
$msg = JText::_( 'NO IMAGE ID GIVEN' );
$link = 'index.php?option=com_test&controller=dealers';
$mainframe->redirect($link, $msg);
}
## Connecting the database
$db = JFactory::getDBO();
## Creating the quesry to get the image name and extention
$sql = 'SELECT image'.(int)$image.' AS image FROM #__test WHERE id = '.(int)$cid.'';
$db->setQuery($sql);
$item = $db->loadObject();
if($item->image == ''){
$msg = JText::_( 'NO IMAGES TEST' );
$link = 'index.php?option=' .$option. '&task=edit&cid[]='.(int)$cid;
$mainframe->redirect($link, $msg);
}
##Define the path to the image and check if it's there.
$sql = 'SELECT imagepath FROM #__test_config WHERE id = 1';
$db->setQuery($sql);
$data = $db->loadObject();
## Making an array of files..
$files = array( $data->imagepath.$item->image, $data->imagepath.'mi'.$item->image);
## Deleteing the files (image and thumbnail)
JFile::delete( $files );
$query = 'UPDATE #__test
SET image'.(int)$image.' = ""
WHERE id = $id';
## Do the query now
$db->setQuery($query);
## When query goes wrong.. Show message with error.
if (!$db->query()) {
$this->setError($this->_db->getErrorMsg());
return false;
}
dump($data->imagepath, 'Variable Name');
$msg = JText::_( 'IMAGE DELETED' );
$link = 'index.php?option=' .$option. '&task=edit&cid[]='.(int)$cid;
$mainframe->redirect($link, $msg);
}
Habe ich etwas vergessen, oder warum greift die Funktion nicht?
Lesezeichen