0

我一直在寻找解决这个问题的方法,因此没有找到。我希望有人能够帮助我解决这个问题。

我有这个 PHP 脚本,它可以获取发布的文件、上传、重命名并移动到一个目录中:

<?php

    $fileName   = $_POST['fileName'];

    if (!$fileName) $fileName = $distFile.rand(1,999)."-".basename($_COOKIE["email"]);
    $distFile   = dirname(__FILE__).'/audio/'.$fileName.'.wav';
    $error      = 'N';
    $message    = 'Your song was uploaded!';

    if (!isset($_FILES['wav']) || $_FILES['wav']['error'] > 0) {
        $error = 'Y';
        $message = 'Error while uploading. Error code: '.$_FILES['wav']['error'];
    } else {

        $res = @move_uploaded_file($_FILES['wav']['tmp_name'], $distFile);

        if (!$res) {
            $error = 'Y';
            $message = 'Unable to create the file.';
        }
    }

    echo '
        <?xml version="1.0"?>
        <response>
            <error value="'.$error.'" />
            <message>'.htmlspecialchars($message).'</message>
        </response>
    ';

?>

一切正常,但是每当我尝试实现标头重定向时(像这样):

<?php

    $fileName   = $_POST['fileName'];

    if (!$fileName) $fileName = $distFile.rand(1,999)."-".basename($_COOKIE["email"]);
    $distFile   = dirname(__FILE__).'/audio/'.$fileName.'.wav';
    $error      = 'N';
    $message    = 'Your song was uploaded!';
    if($filename) {
        header('Location: http://google.co.uk');
    }

我无法刷新页面。我必须指出,该脚本与我尝试重新加载的页面位于不同的文件中。该脚本位于文件中saveWav.php,我正在尝试重新加载index.php.

4

1 回答 1

0

我希望您将代码替换为此

$fileName   = $_POST['fileName'];

if (!$fileName) 
{
    $fileName = $distFile.rand(1,999)."-".basename($_COOKIE["email"]);
    $distFile   = dirname(__FILE__).'/audio/'.$fileName.'.wav';
    $error      = 'N';
    $message    = 'Your song was uploaded!';
}
else
{
    header('Location: http://google.co.uk');
}
于 2013-06-14T12:38:41.900 回答