2011-01-09 14 views
0

Wie zeige ich die sterben() Nachricht in If ($ erlaubt) an der gleichen Stelle wie move_uploaded_file Ergebnis?Display sterben ('Nachricht') Problem

<?php 
    $destination_path = $_SERVER['DOCUMENT_ROOT'].'/uploads/'; 

    $allowed[] = 'image/gif'; 
    $allowed[] = 'image/jpeg'; 
    $allowed[] = 'image/pjpeg'; 
    $allowed[] = 'image/png'; 

    if (!in_array($_FILES['myfile']['type'], $allowed)) { 
    die('Wrong file type!'); 
    } 

    $result = 0; 

    $now = time(); 

    $ext = end(explode(".", $_FILES['myfile']["name"])); 

    $filename = ($_FILES['myfile'][0].$now.".".$ext); 

    if(@move_uploaded_file($_FILES['myfile']['tmp_name'], $destination_path .$filename)) { 
    $result = 1; 
    } 

    sleep(1); 
?> 

<script language="javascript" type="text/javascript"> window.top.window.stopUpload('<? php echo $result; ?>', '<?php echo $filename; ?>');</script> 

Javascript move_uploaded_file Ergebnis anzuzeigen:

function stopUpload(success,filename){ 
    var result = ''; 
    if (success == 1){ 
    result = '<span class="msg">Great!<\/span><br/><br/>'; 
    } 
    else { 
    result = '<span class="emsg">Not so great.<\/span><br/><br/>'; 
    } 
+0

Ihre Frage nicht, aber das funktioniert nicht '$ ext = Ende (explode (, $ _FILES [ 'myfile'] [ "name "])"."); 'entweder teilen Sie das in zwei Zeilen oder verwenden Sie pathinfo –

+0

Funktioniert nicht? Wofür? Die hochgeladenen Dateien erhalten den Namen "timestamp.ext" zB 1294601292.jpg – KilgoreTrout

Antwort

0

meinst du in der gleichen Bedingung?

if (in_array($_FILES['myfile']['type'], $allowed) && @move_uploaded_file($_FILES['myfile']['tmp_name'], $destination_path .$filename)) { 
    $result = 1; 
} else { 
    die("Error while uploding file"); 
} 
+0

Yeah! Vielen Dank. Works .... musste jedoch Ihre anderen Würfel entfernen. Danke noch einmal – KilgoreTrout

0

hinzufügen dritten $result Zustand (-1, zum Beispiel), dann statt die(message);, tun $result = -1; exit(0);. Ändern Sie das JavaScript so else if (success == -1) { result = 'Wrong file type!' }