php请求完成后激活标题
我目前正在一个网站上工作,用户可以上传高达10mb的图像。当用户按upload时,文件存储在服务器上的一个目录中,然后通过使用页眉重定向页面。注意,我还将ob start放在脚本的开头。我遇到的问题是,头重定向在请求完成之前激活,因此用户会注销,或者发生内部服务器错误。删除大文件时也会发生同样的情况。我已经尝试过删除重定向,它很好,所以我确信这就是问题所在。是否只有在php请求图像上传完成后,才有办法获得标题重定向 谢谢 编辑:代码示例php请求完成后激活标题,php,redirect,header,buffer,Php,Redirect,Header,Buffer,我目前正在一个网站上工作,用户可以上传高达10mb的图像。当用户按upload时,文件存储在服务器上的一个目录中,然后通过使用页眉重定向页面。注意,我还将ob start放在脚本的开头。我遇到的问题是,头重定向在请求完成之前激活,因此用户会注销,或者发生内部服务器错误。删除大文件时也会发生同样的情况。我已经尝试过删除重定向,它很好,所以我确信这就是问题所在。是否只有在php请求图像上传完成后,才有办法获得标题重定向 谢谢 编辑:代码示例 if (empty($errors)) { // G
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
}
试试这个
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(!@copy($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
}
}
代码示例?上传代码上面有重定向代码吗?这将是一个明显的原因。@MichaelRushton,是的,我在最后有它。它也只在大文件上,很奇怪!我尝试了你的代码,我得到了文件错误上传消息尝试删除@符号行如果@移动上传的文件$tmp\U名称,$location?如果这不起作用,新代码会起作用,请查看。那个move_上传的文件似乎是为了另一个目的:PMerrick,没有骰子?刚喝了杯咖啡。我不想打扰你,但那东西似乎还有其他问题。职能应该发挥作用。只是想问一下,您是在本地工作还是在主机服务器上工作?