seb123 Posted December 11, 2009 Share Posted December 11, 2009 Hello all, I tryed the options of http://www.phpfreaks.com/forums/index.php?topic=232178.0, but the script is not working in the file below. Can anyone give me the solution for implementing the $imgNumb++; Note: i use joomla. In the form files i use this code: <?php for($i=1; $i<=$aantalpic; $i++){ echo "<tr><td>Images $i</td><td> <input type='file' name='userfile$i' id='url' class='bginput'></td></tr>"; } ?> This works... Here the code of the uploadfile (the file works if you upload only one file. <?php define( "_VALID_MOS", 1 ); // File Upload if (isset($_FILES['userfile'])) { $cfg = $_POST; $css = $cfg['css']; $objid = $cfg['objid']; // is this the first image of this object? $sql = "SELECT count(id) FROM #__botenaanbod_images WHERE objid = $objid"; $database->setQuery($sql); $result = $database->loadResult(); $pn = ( $result == 0 )? 1 : ($result+1); $src_file = (isset($_FILES['userfile']['tmp_name']) ? $_FILES['userfile']['tmp_name'] : ""); // check individual settings $cfg['picpath'] = (trim($cfg['picpath']) != trim($ea_picpath))? $cfg['picpath'] : $ea_picpath; $cfg['maxpicsize'] = ($cfg['maxpicsize'] != $ea_maxpicsize)? $cfg['maxpicsize'] : $ea_maxpicsize; $cfg['imgwidth'] = ($cfg['imgwidth'] != $ea_imgwidth)? $cfg['imgwidth'] : $ea_imgwidth; $cfg['imgheight'] = ($cfg['imgheight'] != $ea_imgheight)? $cfg['imgheight'] : $ea_imgheight; $cfg['imageprtn'] = (isset($cfg['imgprtn']))? 1 : 0; $cfg['imgqulty'] = ($cfg['imgqulty'] != $ea_imgqulty)? $cfg['imgqulty'] : $ea_imgqulty; $cfg['createTb'] = (isset($cfg['createthumb']))? 1:0; $cfg['tbwidth'] = ($cfg['tbwidth'] != $ea_tbwidth)? $cfg['tbwidth'] : $ea_tbwidth; $cfg['tbheight'] = ($cfg['tbheight'] != $ea_tbheight)? $cfg['tbheight'] : $ea_tbheight; $cfg['thumbprtn'] = (isset($cfg['tbprtn']))? 1 : 0; $cfg['tbqulty'] = ($cfg['tbqulty'] != $ea_tbqulty)? $cfg['tbqulty'] : $ea_tbqulty; $dest_dir = $mosConfig_absolute_path.$cfg['picpath']; $type = explode('.',strtolower($_FILES['userfile']['name'])); $file['type'] = '.'.$type[1]; $file['name'] = "ea".time(); $dest_file = $dest_dir.$file['name'].$file['type']; $file['tbname'] = "tea".time(); $dest_thmb = $dest_dir.$file['tbname'].$file['type']; if (eregi("[^0-9a-zA-Z_ ]", $cfg['title'])) { echo "<script> alert('"._EAB_GL_TITLEERROR."'); window.history.go(-1);</script>\n"; exit(); } if(filesize($src_file) > (intval($cfg['maxpicsize']) * 1000)) { echo "<script> alert('"._EAB_GL_UTB."'); window.history.go(-1);</script>\n"; exit(); } if (file_exists($dest_file)) { echo "<script> alert('"._EAB_GL_FAE."'); window.history.go(-1);</script>\n"; exit(); } if ( (strcasecmp($file['type'],".gif")) && (strcasecmp($file['type'],".jpg")) && (strcasecmp($file['type'],".png")) ) { echo "<script>alert('The file can be gif, jpg, png'); window.history.go(-1);</script>\n"; exit(); // AVI, MPEG hinzufügen -> Active-X control für MSIE -> classid="CLSID:05589FA1-C356-11CE-BF01-00AA0055595A" } $error = ""; if($file['type'] == ".gif" || $file['type'] == ".jpg" || $file['type'] == ".png" ) { # create images & thumbs $error = resizeIMG(0,$src_file,$dest_file,$cfg['imgwidth'],$cfg['imgheight'],$cfg['imageprtn'],$cfg['imgqulty']); if($cfg['createTb'] == 1) { $error .= resizeIMG(1,$src_file,$dest_thmb,$cfg['tbwidth'],$cfg['tbheight'],$cfg['thumbprtn'],$cfg['tbqulty']); } } else{ if(@copy($src_file,$dest_file)) $error = ""; else $error = _EAB_GL_UFS; } if($error == "") { $pic = new EAImage($database); if (!$pic->bind( $_POST )) { echo "<script> alert('".$pic->getError()."'); window.history.go(-1); </script>\n"; exit(); } $pic->title = trim($cfg['title']); $pic->description = trim($cfg['description']); $pic->fname = $file['name']; $pic->type = $file['type']; $pic->path = trim($cfg['picpath']); $pic->owner = $my->id; $pic->ordering = 0; $pic->publish = 1; if (!$pic->check()) { echo "<script> alert('".$pic->getError()."'); window.history.go(-1); </script>\n"; exit(); } if (!$pic->store()) { echo "<script> alert('".$pic->getError()."'); window.history.go(-1); </script>\n"; exit(); } $pic->checkin(); $pic->updateOrder( "objid=$objid AND type='$pic->type'" ); $msg = sprintf (_EA_GL_UPLOADSUCCESS, $pn); //$msg = _EA_GL_UPLOADSUCCESS; mosRedirect("admin.gallery.html.php?action=manage&css=".$css."&objid=".$pic->objid."&msg=".$msg."&uid=".$my->id."&pn=".$pn); } else{ echo "<script> alert('"._EAB_GL_UFS."'); window.history.go(-1); </script>\n"; } } else{ echo "<script> alert('"._EAB_GL_NOFILE."'); window.history.go(-1); </script>\n"; } # Thanks to Arthur Konze for this function ################################################## function resizeIMG($is_thmb,$src_file,$dest_file,$width,$height,$prop,$quality){ global $ea_gplib, $ea_watermark, $mosConfig_live_site; $imagetype = array( 1 => 'GIF', 2 => 'JPG', 3 => 'PNG' ); $imginfo = getimagesize($src_file); if ($imginfo == null) { $error = _EAB_GL_NOFILE; return $error; } $imginfo[2] = $imagetype[$imginfo[2]]; // GD can only handle JPG & PNG images if ($imginfo[2] != 'JPG' && $imginfo[2] != 'PNG' && ($ea_gplib == 'gd1' || $ea_gplib == 'gd2')) { $error = "ERROR: GD can only handle JPG and PNG files!"; return $error; } // source height/width $srcWidth = $imginfo[0]; $srcHeight = $imginfo[1]; if($prop == 1) { $ratio = $srcHeight / $height; #$ratio = max($srcWidth, $srcHeight) / $new_size; $ratio = max($ratio, 1.0); $destWidth = (int)($srcWidth / $ratio); $destHeight = (int)($srcHeight / $ratio); } else{ $ratio = $srcHeight / $height; #$ratio = max($srcWidth, $srcHeight) / $new_size; $ratio = max($ratio, 1.0); $destWidth = (int)($srcWidth / $ratio); $destHeight = (int)($srcHeight / $ratio); } // Method for thumbnails creation switch ($ea_gplib) { case "gd1" : if (!function_exists('imagecreatefromjpeg')) { $error = _EAB_GL_NOGD; return $error; } if ($imginfo[2] == 'JPG') $src_img = imagecreatefromjpeg($src_file); else $src_img = imagecreatefrompng($src_file); if (!$src_img){ $error = $lang_errors['invalid_image']; return $error; } $dst_img = imagecreate($destWidth, $destHeight); imagecopyresized($dst_img, $src_img, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight); if(!$is_thmb && $ea_watermark){ $wmstr = substr($mosConfig_live_site,7); $wmstr = "(c)" . $wmstr; $ftcolor = imagecolorallocate($dst_img,239,239,239); imagestring ($dst_img, 9,10, $destHeight-20, $wmstr, $ftcolor); } imagejpeg($dst_img, $dest_file, $quality); imagedestroy($src_img); imagedestroy($dst_img); break; case "gd2" : if (!function_exists('imagecreatefromjpeg')) { $error = _EAB_GL_NOGD2; return $error; } if (!function_exists('imagecreatetruecolor')) { $error = "GD2 image library does not support truecolor thumbnailing!"; return $error; } if ($imginfo[2] == 'JPG') $src_img = imagecreatefromjpeg($src_file); else $src_img = imagecreatefrompng($src_file); if (!$src_img){ $error = $lang_errors['invalid_image']; return $error; } $dst_img = imagecreatetruecolor($destWidth, $destHeight); imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight); if(!$is_thmb && $ea_watermark){ $wmstr = substr($mosConfig_live_site,7); $wmstr = "(c)" . $wmstr; $ftcolor = imagecolorallocate($dst_img,239,239,239); imagestring ($dst_img, 9,10, $destHeight-20, $wmstr, $ftcolor); } imagejpeg($dst_img, $dest_file, $quality); imagedestroy($src_img); imagedestroy($dst_img); break; } // Set mode of uploaded picture chmod($dest_file, octdec('644')); // We check that the image is valid $imginfo = getimagesize($dest_file); if ($imginfo == null){ $error = _EAB_GL_NOTHMBCREAT; return $error; } else return; } ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.