Dropzone lädt doppelt hoch

Grunge

Erfahrenes Mitglied
Hey Leute,

Via Dropzone Script lade ich Bilder hoch. Das funktioniert auch prinzipiell ganz gut, nur ist das Problem, dass er mir manche Bilder überspringt oder doppelt abspeichert. Das passiert aber völlig willkürlich, so dass ich nicht so recht weiß, warum und weshalb. Grobe Vermutung wäre, dass das Script "zu schnell" ist oder so.

Zur Erläuterung:
Wenn das Datei Feld NICHT leer ist wird ein Zufalls - Dateiname generiert.

Danach wird das Thumbnail erstellt

und letztendlich das ganze nochmal in die DB eingetragen.

Wie gesagt funktioniert es einwandfrei, nur dass er manchmal doppelte Dateinamen vergibt, und dann logischerweise das Bild nicht hochläd, bzw diesen falschen doppelten Eintrag in die DB mit aufnimmt. Ich weiß aber patou nicht, woran das liegen könnte....

Code:
<?php

include "includes/_db.php";

include "includes/_functions.php";

$ds          = DIRECTORY_SEPARATOR;  //1



$storeFolder = 'usr_timeline_img';   //2

$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';

if (!empty($_FILES)) {

        $charactersLength = strlen($characters);

    $randomString = '';

    for ($i = 0; $i < 128; $i++) {

        $randomString .= $characters[rand(0, $charactersLength - 1)];

    }

    $img = explode(".", $_FILES['file']['name']);

    $file = $img[1];



    $tempFile = $_FILES['file']['tmp_name'];          //3             

     

    $targetPath = dirname( __FILE__ ) . $ds. $storeFolder . $ds;  //4

     

    $targetFile =  $targetPath. $randomString.".".$file;  //5



    move_uploaded_file($tempFile,$targetFile); //6

   

    //Thumbnail erstellen!

$imagefile = 'usr_timeline_img/'.$randomString.".".$file;

$imagesize = getimagesize($imagefile);

$imagewidth = $imagesize[0];

$imageheight = $imagesize[1];

$imagetype = $imagesize[2];





switch ($imagetype)

{

    // Bedeutung von $imagetype:

    // 1 = GIF, 2 = JPG, 3 = PNG, 4 = SWF, 5 = PSD, 6 = BMP, 7 = TIFF(intel byte order), 8 = TIFF(motorola byte order), 9 = JPC, 10 = JP2, 11 = JPX, 12 = JB2, 13 = SWC, 14 = IFF, 15 = WBMP, 16 = XBM

    case 1: // GIF

        $image = imagecreatefromgif($imagefile);

        break;

    case 2: // JPEG

        $image = imagecreatefromjpeg($imagefile);

        break;

    case 3: // PNG

        $image = imagecreatefrompng($imagefile);

        break;

    default:

        die('Unsupported imageformat');

}



// Maximalausmaße

$maxthumbwidth = 150;

$maxthumbheight = 100;

// Ausmaße kopieren, wir gehen zuerst davon aus, dass das Bild schon Thumbnailgröße hat

$thumbwidth = $imagewidth;

$thumbheight = $imageheight;

// Breite skalieren falls nötig

if ($thumbwidth > $maxthumbwidth)

{

    $factor = $maxthumbwidth / $thumbwidth;

    $thumbwidth *= $factor;

    $thumbheight *= $factor;

}

// Höhe skalieren, falls nötig

if ($thumbheight > $maxthumbheight)

{

    $factor = $maxthumbheight / $thumbheight;

    $thumbwidth *= $factor;

    $thumbheight *= $factor;

}

// Thumbnail erstellen

$thumb = imagecreatetruecolor($thumbwidth, $thumbheight);



imagecopyresampled($thumb,$image,0, 0, 0, 0, $thumbwidth, $thumbheight,$imagewidth, $imageheight);



//In Datei speichern

$imagefile = explode("/", $imagefile);

 $thumbfile = 'usr_timeline_img/thumbnails/' . $imagefile[1];

 imagepng($thumb, $thumbfile);



 //Bild in DB eintragen



 //$foto = gettimelinefoto($_COOKIE['ID']);

 $sql = "INSERT INTO social_timeline (timeline_uid, timeline_date, timeline_type, timeline_text, timeline_foto) VALUES ('".$_COOKIE['ID']."', NOW(), 'Foto', '".$randomString.".".$file."', '".$_GET['id']."')";

 $db->query($sql);

 //echo $randomString.".".$file;

 echo $sql;

}

?>
 
Zurück