我在哪里把我的链接放在这个PHP?

时间:2015-02-06 22:40:23

标签: php

这是一个非常微不足道的问题,但我无法弄清楚:

我有这个php脚本

<?php

// If you want to ignore the uploaded files, 
// set $demo_mode to true;

$demo_mode = false;
$upload_dir = 'upload/';
$allowed_ext = array('jpg','jpeg','png','gif');


if(strtolower($_SERVER['REQUEST_METHOD']) != 'post'){
    exit_status('Error! Wrong HTTP method!');
}


if(array_key_exists('pic',$_FILES) && $_FILES['pic']['error'] == 0 ){

    $pic = $_FILES['pic'];

    if(!in_array(get_extension($pic['name']),$allowed_ext)){
        exit_status('Only '.implode(',',$allowed_ext).' files are allowed!');
    }   

    if($demo_mode){

        // File uploads are ignored. We only log them.

        $line = implode('       ', array( date('r'), $_SERVER['REMOTE_ADDR'], $pic['size'], $pic['name']));
        file_put_contents('log.txt', $line.PHP_EOL, FILE_APPEND);

        exit_status('Uploads are ignored in demo mode.');
    }


    // Move the uploaded file from the temporary 
    // directory to the uploads folder:

    if(move_uploaded_file($pic['tmp_name'], $upload_dir.'Bild.jpg')){
        exit_status('File was uploaded successfuly!');      
    }

}

exit_status('Something went wrong with your upload!');


// Helper functions

function exit_status($str){
    echo json_encode(array('status'=>$str));
    exit;
}



function get_extension($file_name){
    $ext = explode('.', $file_name);
    $ext = array_pop($ext);
    return strtolower($ext);
}

?>

完成整个过程后,我想重定向到另一个页面,甚至更好,直接启动另一个脚本。

我尝试插入

header('Location: start_conversion.php');

在最后一次if之后(文件成功上传),但是没有用。 我的错误在哪里?

2 个答案:

答案 0 :(得分:1)

exit_status似乎终止了您的脚本。所以你需要在之前重新定位

也许您可以使用:

function exit_redirect($loc){
    header("Location: $loc",TRUE,302);
    exit;
}

答案 1 :(得分:0)

好的,解决方案是最初添加的javascript。我不得不从那里重定向,然后一切正常。