2012-03-31 5 views
0

Ich arbeite derzeit auf einer Website, wo Benutzer Bilder bis zu 10 MB hochladen können. Wenn die Benutzer auf Upload klicken, wird die Datei in einem Verzeichnis auf dem Server gespeichert und anschließend wird die Seite mithilfe eines Headers umgeleitet. Beachten Sie, dass ich auch ob start() am Anfang des Skripts gesetzt habe. Das Problem, das ich habe, ist, dass die Header-Redirect aktiviert wird, bevor die Anfrage abgeschlossen ist, so dass Benutzer abgemeldet werden, oder ein interner Serverfehler auftritt. Das Gleiche passiert, wenn Sie die große Datei löschen. Ich habe versucht, die Umleitung zu entfernen und es ist in Ordnung, also bin ich mir sicher, dass das das Problem ist. Gibt es eine Möglichkeit, die Header-Weiterleitung erst nach Abschluss der PHP-Anfrage (Image-Upload) zu erhalten?Activate Header nach PHP-Anfrage ist abgeschlossen

Danke!

Edit: Codebeispiel

if (empty($errors)) { 

    // Get the filename minus the file extension: 
$filename = substr($image["name"], 0, strrpos($image["name"], ".")); 
// Append the appropriate extension 
$filename .= $validMimes[$image['type']]; 
$location = "/home/shoplft/users/$user_id/$foldername/$filename"; 
    move_uploaded_file($tmp_name, $location); 




    if($secondcategory=="0") { 


    mysql_query("INSERT INTO products (users_user_id, name, brand, city, country, store, website, price, keywords, productlocation, filename) VALUES ('$user_id', '$productname', '$productbrand', '$city', '$country', '$store', '$website', '$price', '$tagwords', '$location', '$filename')") or die('Invalid query: ' . mysql_error()); 

    $pic_id = mysql_insert_id(); 

    mysql_query("INSERT INTO categories (products_products_id, products_users_user_id, category) VALUES('$pic_id', '$user_id', '$firstcategory')"); 

    if(!empty($price)) { 

     mysql_query("INSERT INTO svalues (products_products_id, products_users_user_id, svalue) VALUES ('$pic_id', '$user_id', '$price') "); 

    } 




    } 



    else { 

    mysql_query("INSERT INTO products (users_user_id, name, brand, city, country, store, website, price, keywords, productlocation, filename) VALUES ('$user_id', '$productname', '$productbrand', '$city', '$country', '$store', '$website', '$price', '$tagwords', '$location', '$filename')") or die('Invalid query: ' . mysql_error()); 

    $pic_id = mysql_insert_id(); 

mysql_query("INSERT INTO categories (products_products_id, products_users_user_id, category) VALUES('$pic_id', '$user_id', '$firstcategory')"); 
mysql_query("INSERT INTO categories (products_products_id, products_users_user_id, category) VALUES('$pic_id', '$user_id', '$secondcategory')"); 

    if(!empty($price)) { 

     mysql_query("INSERT INTO svalues (products_products_id, products_users_user_id, svalue) VALUES ('$pic_id', '$user_id', '$price') "); 

    } 


    } 

header("Location: product.php?id=$pic_id");//prolly should separate data processing from output 

}  
+2

Codebeispiel? Haben Sie den Weiterleitungscode über dem Upload-Code? Das wird ein offensichtlicher Grund sein. – MichaelRushton

+0

@MichaelRushton, ja, ich habe es am Ende. Es ist nur auf großen Dateien auch, es ist komisch! – MerrickC

Antwort

0

Versuchen Sie, diese

if (empty($errors)) { 

    // Get the filename minus the file extension: 
$filename = substr($image["name"], 0, strrpos($image["name"], ".")); 
// Append the appropriate extension 
$filename .= $validMimes[$image['type']]; 
$location = "/home/shoplft/users/$user_id/$foldername/$filename"; 
if([email protected]($tmp_name, $location)) 
{ 
$errors[] = 'Error'; 
} 

if (empty($errors)) 
{ 




    if($secondcategory=="0") { 


    mysql_query("INSERT INTO products (users_user_id, name, brand, city, country, store, website, price, keywords, productlocation, filename) VALUES ('$user_id', '$productname', '$productbrand', '$city', '$country', '$store', '$website', '$price', '$tagwords', '$location', '$filename')") or die('Invalid query: ' . mysql_error()); 

    $pic_id = mysql_insert_id(); 

    mysql_query("INSERT INTO categories (products_products_id, products_users_user_id, category) VALUES('$pic_id', '$user_id', '$firstcategory')"); 

    if(!empty($price)) { 

     mysql_query("INSERT INTO svalues (products_products_id, products_users_user_id, svalue) VALUES ('$pic_id', '$user_id', '$price') "); 

    } 




    } 



    else { 

    mysql_query("INSERT INTO products (users_user_id, name, brand, city, country, store, website, price, keywords, productlocation, filename) VALUES ('$user_id', '$productname', '$productbrand', '$city', '$country', '$store', '$website', '$price', '$tagwords', '$location', '$filename')") or die('Invalid query: ' . mysql_error()); 

    $pic_id = mysql_insert_id(); 

mysql_query("INSERT INTO categories (products_products_id, products_users_user_id, category) VALUES('$pic_id', '$user_id', '$firstcategory')"); 
mysql_query("INSERT INTO categories (products_products_id, products_users_user_id, category) VALUES('$pic_id', '$user_id', '$secondcategory')"); 

    if(!empty($price)) { 

     mysql_query("INSERT INTO svalues (products_products_id, products_users_user_id, svalue) VALUES ('$pic_id', '$user_id', '$price') "); 

    } 


    } 

header("Location: product.php?id=$pic_id");//prolly should separate data processing from output 
} 
} 
+0

Merrick? Ist es jetzt in Ordnung? Gosh ich spät für Kaffee lol: P – Xfile

+0

Ich versuchte Ihren Code, und ich bekomme die "Datei Fehler Upload" Nachricht – MerrickC

+0

haha ​​für Ihren Kaffee gehen, ich werde immer noch hier sein! – MerrickC