Guten morgen alle zusammen,
habt Ihr auch alle schön geschlafen? Super, dann kann mir bestimmt auch jemand weiter helfen, ansonsten werde ich ein JOOMLA! tabellenlastiger Template Entwickler.
Ich schreibe gerade mein erstes Plugin für WordPress, es soll ein Content-Slider werden, mit bestimmten Funktionen. Es funktioniert bisher alles wunderbar, bist auf eine kleine Sache. Ich will vor dem hochladen angeben, wie groß das Bild sein soll, also die width und height.
Beim hochladen bekomme ich aber einen Fehler, der scheinbar mit Rechten zusammenhängt:
Warning: imagejpeg() [function.imagejpeg]: Unable to open 'http://localhost/developer/wp-content/uploads/2011/04/neuesBild.jpg' for writing: Invalid argument in C:\xampp\htdocs\developer\wp-content\plugins\Content-Slider-WP\imgSizeClass.php on line 40
Mein Script dazu:
<?php
function uploadImage(){
include("content-slider-form.php");
//Das speichern des Formulars abfangen und in DB schreiben
if('insert' == $_POST['action']) {
global $wpdb;
$img_file = $_FILES['file']['name'];
$neuImg = WP_CONTENT_URL.'/uploads/2011/04/'.$img_file;
$imgSize = $_POST['size'];
$description = $_POST['content_slider_description'];
$wpdb->insert( 'wp_content_slider_table', array('img_loc' => $img_file, 'description' => $description), array( '%s' ) );
//dir_rekursiv('http://localhost/developer/wp-content/uploads');
uploadFile();
proportionalSizePixel($neuImg, $imgSize);
}
}
//Dateien hochladen mit dem Formular von dem Computer
function uploadFile(){
if($_FILES["file"]["name"]!='') {
$upload = wp_upload_bits($_FILES["file"]["name"], null, file_get_contents($_FILES["file"]["tmp_name"]));
//proportionalSizePixel($neuImg, $imgSize);
}
}
function proportionalSizePixel($neuImg, $imgSize){
include("imgSizeClass.php");
$image = new imgSizeClass();
$image->load($neuImg);
$image->resizeToWidth($imgSize);
$image->save(WP_CONTENT_URL.'/uploads/2011/04/neuesBild.jpg');
}
?>
Alles anzeigen
Und noch die Klasse
<?php
class imgSizeClass {
var $image;
var $image_type;
function load($filename) {
$image_info = getimagesize($filename);
$this->image_type = $image_info[2];
if( $this->image_type == IMAGETYPE_JPEG ) {
$this->image = imagecreatefromjpeg($filename);
} elseif( $this->image_type == IMAGETYPE_GIF ) {
$this->image = imagecreatefromgif($filename);
} elseif( $this->image_type == IMAGETYPE_PNG ) {
$this->image = imagecreatefrompng($filename);
}
}
function save($filename, $image_type=IMAGETYPE_JPEG, $compression=75, $permissions=null) {
if( $image_type == IMAGETYPE_JPEG ) {
imagejpeg($this->image,$filename,$compression);
} elseif( $image_type == IMAGETYPE_GIF ) {
imagegif($this->image,$filename);
} elseif( $image_type == IMAGETYPE_PNG ) {
imagepng($this->image,$filename);
}
if( $permissions != null) {
chmod($filename,$permissions);
}
}
function output($image_type=IMAGETYPE_JPEG) {
if( $image_type == IMAGETYPE_JPEG ) {
imagejpeg($this->image);
} elseif( $image_type == IMAGETYPE_GIF ) {
imagegif($this->image);
} elseif( $image_type == IMAGETYPE_PNG ) {
imagepng($this->image);
}
}
function getWidth() {
return imagesx($this->image);
}
function getHeight() {
return imagesy($this->image);
}
function resizeToHeight($height) {
$ratio = $height / $this->getHeight();
$width = $this->getWidth() * $ratio;
$this->resize($width,$height);
}
function resizeToWidth($width) {
$ratio = $width / $this->getWidth();
$height = $this->getheight() * $ratio;
$this->resize($width,$height);
}
function scale($scale) {
$width = $this->getWidth() * $scale/100;
$height = $this->getheight() * $scale/100;
$this->resize($width,$height);
}
function resize($width,$height) {
$new_image = imagecreatetruecolor($width, $height);
imagecopyresampled($new_image, $this->image, 0, 0, 0, 0, $width, $height, $this->getWidth(), $this->getHeight());
$this->image = $new_image;
}
}
?>
Alles anzeigen
Kann mir da bitte einer weiter helfen, ich dreh mich im Kreis. Hab es lokal sowie auf einem Server getestet. Die Klasse ohne WordPress funktioniert wunderbar.
Grüße Jochen