在这个php中我应该把我的链接放在哪里?

在这个php中我应该把我的链接放在哪里?,php,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'])

这是一个非常琐碎的问题,但我无法理解:

我有这张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);
}

?>
在最后一次if之后(文件上传成功),但这不起作用。
我的错误在哪里?

退出\u状态显示为终止脚本。所以你需要把重定向放在前面

或许您可以使用:

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

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

定义“没有工作”?脚本运行了,但没有重定向。我忘了提到我已经尝试过了。我要给特克斯打一针
function exit_redirect($loc){
    header("Location: $loc",TRUE,302);
    exit;
}