beste,
mijn upload class werkt goed het bestand uit 1 woord bestaat
Maar als mijn bestands naam vb Schermafbeelding 2012-03-14 om 20.13.11.png is dan loopt het mis
dan krijg ik de melding
Error Invalid Image Type
PHP Code:
<?
#######################################################################
# $upload = new upload_class("uploadedfile","../Borden/");
#
class upload_class
{
var $field_name;
var $target_path;
var $name;
var $resize = false;
var $resizeType = 1; // 0 = vaste maten, 1 = variabel
var $width;
var $height;
var $type;
var $custom_types;
function upload_class($field,$target)
{
$this->target_path = $target;
$this->field_name = $field;
}
function file()
{
if($this->php_check() == true)
{
if($this->file_check() == true)
{
$this->move();
}
else
{
echo "<script>alert('Dit bestands type is niet toegestaan')</script>";
}
}
else {
echo "<script>alert('Het is niet toegestaan om PHP bestanden te uploaden !')</script>";
}
}
function move()
{
$input_name = $_FILES[$this->field_name]['name'];
$file_name = $this->genRandomString().rand(5, 15).rand(5, 15).rand(5, 15).rand(5, 15).strstr($input_name, '.');
$this->name = $this->target_path . $file_name;
#if(move_uploaded_file($_FILES[$this->field_name]['tmp_name'], $this->name))
if(copy($_FILES[$this->field_name]['tmp_name'], $this->name))
{
$this->name = str_replace("../","",$this->name); // verwijderd de directory tags
if($this->resize == true)
{
$this->makeimage($this->name);
}
}
else
{
echo "Er is een fout opgetreden bij het uploaden van het bestand probeer later nog eens<br/>";exit;
}
}
function php_check()
{
$clean = true;
$blocklijst = array(".php",".php5",".xhtml",".dhtml",".PHP",".php3");
foreach ($blocklijst as $item)
{
if(preg_match("/$item\$/i", $_FILES[$this->field_name]['name']))
{
$clean = false;
}
}
return $clean;
}
function file_check()
{
$allowed = array("image/jpeg", "image/jpg", "image/pjpeg", "image/gif","image/png");
#$imageinfo = getimagesize($_FILES[$this->field_name]['tmp_name']);
$header = $_FILES[$this->field_name]['type'];
# if (in_array($imageinfo['mime'], $allowed))
# {
if (in_array($header, $allowed))
{
return true;
}
else {
return false;
}
#} else {
# return false;
# }
}
function genRandomString() {
$length = 10;
$characters = "0123456789abcdefghijklmnopqrstuvwxyz";
$string = "";
for ($p = 0; $p < $length; $p++) {
$string .= $characters[mt_rand(0, strlen($characters))];
}
return $string;
}
function makeimage($filename)
{
// hier wordt gecontrolleerd of filename ../ directory tags bevat
// anders wordt de image type niet correct gepakt
#copy("uploads_normale/rrpusrd0xo712146.jpg", "upload_thumbnail/rrpusrd0xo712146.jpg");
if (strpos($filename, "../") !== false) {
$edit_filename = str_replace("../","",$filename); // verwijderd de directory tags
$image_type = strstr($edit_filename, '.'); // pakt vervolgens de image type
}
else
{
$image_type = strstr($filename, '.');
}
switch($image_type) {
case '.jpg':
$source = imagecreatefromjpeg($filename);
break;
case '.jpeg':
$source = imagecreatefromjpeg($filename);
break;
case '.png':
$source = imagecreatefrompng($filename);
break;
case '.gif':
$source = imagecreatefromgif($filename);
break;
default:
echo("Error Invalid Image Type ");
die;
break;
}
$fullpath = $filename;
list($org_width, $org_height) = getimagesize($fullpath);
if ($this->resizeType == 0)
{
// resize op vaste maten
$newX = $this->width;
$newY = $this->height;
}
else
{
$percentage = ($org_width > $org_height) ? ($this->width / $org_width) : ($this->width / $org_height);
$newX = round($org_width * $percentage);
$newY = round($org_height * $percentage);
}
$thumb = imagecreatetruecolor($newX, $newY);
if(($image_type == ".gif") or ($image_type == ".png"))
{
// Indien het om een gif of png bestand gaat zal deze extra gerenderd worden
// zodat het plaatje niet automatisch een zwarte achtergrond krijgt.
imagealphablending($thumb, false);
imagesavealpha($thumb,true);
$transparent = imagecolorallocatealpha($thumb, 255, 255, 255, 127);
imagefilledrectangle($thumb, 0, 0, $newX, $newY, $transparent);
}
imagecopyresampled($thumb, $source, 0, 0, 0, 0, $newX, $newY, $org_width, $org_height);
imagejpeg($thumb, $fullpath, 100);
}
}
?>
- upload class error
-
14-03-2012, 19:21 #1
- Berichten
- 161
- Lid sinds
- 13 Jaar
upload class error
-
In de schijnwerper
-
14-03-2012, 19:22 #2
- Berichten
- 94
- Lid sinds
- 13 Jaar
Re: upload class error
dat komt door de punten, die ziet hij als extensie
-
14-03-2012, 19:32 #3
- Berichten
- 161
- Lid sinds
- 13 Jaar
Re: upload class error
is het mogelijk dat deze dan wel het plaatje upload ?
-
14-03-2012, 19:35 #4
- Berichten
- 94
- Lid sinds
- 13 Jaar
Re: upload class error
ik weet het niet precies,
maar als je die "die" eruit haalt misschien:
PHP Code:switch($image_type) {
case '.jpg':
$source = imagecreatefromjpeg($filename);
break;
case '.jpeg':
$source = imagecreatefromjpeg($filename);
break;
case '.png':
$source = imagecreatefrompng($filename);
break;
case '.gif':
$source = imagecreatefromgif($filename);
break;
default:
echo("Error Invalid Image Type ");
//die;
break;
}
-
14-03-2012, 19:59 #5
- Berichten
- 691
- Lid sinds
- 15 Jaar
Re: upload class error
Kleine aanpassing en het zou moeten werken:
PHP Code:<?
#######################################################################
# $upload = new upload_class("uploadedfile","../Borden/");
#
class upload_class
{
var $field_name;
var $target_path;
var $name;
var $resize = false;
var $resizeType = 1; // 0 = vaste maten, 1 = variabel
var $width;
var $height;
var $type;
var $custom_types;
function upload_class($field,$target)
{
$this->target_path = $target;
$this->field_name = $field;
}
function file()
{
if($this->php_check() == true)
{
if($this->file_check() == true)
{
$this->move();
}
else
{
echo "<script>alert('Dit bestands type is niet toegestaan')</script>";
}
}
else {
echo "<script>alert('Het is niet toegestaan om PHP bestanden te uploaden !')</script>";
}
}
function move()
{
$input_name = $_FILES[$this->field_name]['name'];
$file_name = $this->genRandomString().rand(5, 15).rand(5, 15).rand(5, 15).rand(5, 15).strstr($input_name, '.');
$this->name = $this->target_path . $file_name;
#if(move_uploaded_file($_FILES[$this->field_name]['tmp_name'], $this->name))
if(copy($_FILES[$this->field_name]['tmp_name'], $this->name))
{
$this->name = str_replace("../","",$this->name); // verwijderd de directory tags
if($this->resize == true)
{
$this->makeimage($this->name);
}
}
else
{
echo "Er is een fout opgetreden bij het uploaden van het bestand probeer later nog eens<br/>";exit;
}
}
function php_check()
{
$clean = true;
$blocklijst = array(".php",".php5",".xhtml",".dhtml",".PHP",".php3");
foreach ($blocklijst as $item)
{
if(preg_match("/$item\$/i", $_FILES[$this->field_name]['name']))
{
$clean = false;
}
}
return $clean;
}
function file_check()
{
$allowed = array("image/jpeg", "image/jpg", "image/pjpeg", "image/gif","image/png");
#$imageinfo = getimagesize($_FILES[$this->field_name]['tmp_name']);
$header = $_FILES[$this->field_name]['type'];
# if (in_array($imageinfo['mime'], $allowed))
# {
if (in_array($header, $allowed))
{
return true;
}
else {
return false;
}
#} else {
# return false;
# }
}
function genRandomString() {
$length = 10;
$characters = "0123456789abcdefghijklmnopqrstuvwxyz";
$string = "";
for ($p = 0; $p < $length; $p++) {
$string .= $characters[mt_rand(0, strlen($characters))];
}
return $string;
}
function makeimage($filename)
{
// hier wordt gecontrolleerd of filename ../ directory tags bevat
// anders wordt de image type niet correct gepakt
#copy("uploads_normale/rrpusrd0xo712146.jpg", "upload_thumbnail/rrpusrd0xo712146.jpg");
if (strpos($filename, "../") !== false) {
$edit_filename = str_replace("../","",$filename); // verwijderd de directory tags
$image_type = strstr($edit_filename, '.'); // pakt vervolgens de image type
}
else
{
$image_type = pathinfo($filename, PATHINFO_EXTENSION);
}
switch($image_type) {
case 'jpg':
$source = imagecreatefromjpeg($filename);
break;
case 'jpeg':
$source = imagecreatefromjpeg($filename);
break;
case 'png':
$source = imagecreatefrompng($filename);
break;
case 'gif':
$source = imagecreatefromgif($filename);
break;
default:
echo("Error Invalid Image Type ");
die;
break;
}
$fullpath = $filename;
list($org_width, $org_height) = getimagesize($fullpath);
if ($this->resizeType == 0)
{
// resize op vaste maten
$newX = $this->width;
$newY = $this->height;
}
else
{
$percentage = ($org_width > $org_height) ? ($this->width / $org_width) : ($this->width / $org_height);
$newX = round($org_width * $percentage);
$newY = round($org_height * $percentage);
}
$thumb = imagecreatetruecolor($newX, $newY);
if(($image_type == ".gif") or ($image_type == ".png"))
{
// Indien het om een gif of png bestand gaat zal deze extra gerenderd worden
// zodat het plaatje niet automatisch een zwarte achtergrond krijgt.
imagealphablending($thumb, false);
imagesavealpha($thumb,true);
$transparent = imagecolorallocatealpha($thumb, 255, 255, 255, 127);
imagefilledrectangle($thumb, 0, 0, $newX, $newY, $transparent);
}
imagecopyresampled($thumb, $source, 0, 0, 0, 0, $newX, $newY, $org_width, $org_height);
imagejpeg($thumb, $fullpath, 100);
}
}
?>
-
14-03-2012, 22:48 #6
- Berichten
- 158
- Lid sinds
- 13 Jaar
Re: upload class error
Ook niet vergeten je enctype van je form op multipart/form-data te zetten. Anders krijg je standaard een error.
-
15-03-2012, 05:59 #7
- Berichten
- 750
- Lid sinds
- 15 Jaar
Re: upload class error
Php pakt zo te zien aan de strstr functie de eerste volgende punt .
Vervang
$image_type=strstr($edit_filename,'.');//paktvervolgensdeimagetype
Eens met
$parts = array_reverse(explode('.', $edit_type));
$image_type=$parts[0];
P.s niet getest maar het zou iets deze richting moeten wezen
-
16-03-2012, 14:25 #8
- Berichten
- 161
- Lid sinds
- 13 Jaar
Re: upload class error
allemaal alvast bedankt het werkt :)
Plaats een
- + Advertentie
- + Onderwerp
Marktplaats
Webmasterforum
- Websites algemeen
- Sitechecks
- Marketing
- Domeinen algemeen
- Waardebepaling
- CMS
- Wordpress
- Joomla
- Magento
- Google algemeen
- SEO
- Analytics
- Adsense
- Adwords
- HTML / XHTML
- CSS
- Programmeren
- PHP
- Javascript
- JQuery
- MySQL
- Ondernemen algemeen
- Belastingen
- Juridisch
- Grafisch ontwerp
- Hosting Algemeen
- Hardware Info
- Offtopic