$_GET 无法在我的 php 上运行

$_GET not working on my php

我将我的 PHP 调用到我的 javascript 代码中,我可以知道为什么 $_GET 在我的 PHP 文件中不起作用吗?

我的 URL 是:localhost/img/index.php?fname=johndoe

Javascript 在我的 index.php 里面是:

<script src="uploadname.js"></script>
<script type="text/javascript">
$(document).ready(
    function()
    {
        $(\'#redactor_content\').redactor({
            imageUpload: \'uploadimage.php\',
            minHeight: 200 // pixels
        });
    }
);
</script> 

php 文件 uploadimage.php

<?php

    $fname=$_GET['fname'];
    $dir = '../assets/uploads/r/';
    $sysUrl = lc('sysUrl');

    $_FILES['file']['type'] = strtolower($_FILES['file']['type']);

    if ($_FILES['file']['type'] == 'image/png'
    || $_FILES['file']['type'] == 'image/jpg'
    || $_FILES['file']['type'] == 'image/gif'
    || $_FILES['file']['type'] == 'image/jpeg'
    || $_FILES['file']['type'] == 'image/pjpeg')
    {
        // setting file's mysterious name
        $filename = $fname.date('YmdHis').'.jpg';
        $file = $dir.$filename;

        // copying
        copy($_FILES['file']['tmp_name'], $file);

        // displaying file
        $array = array(
            'filelink' => $sysUrl.'/assets/uploads/r/'.$filename
        );

        echo stripslashes(json_encode($array));

    }

?>

我使用了上面的代码,但是当我保存文件时它显示空白。什么都没有,请问是什么原因?

您正在尝试读取 uploadimage.php 中的数据,但查询字符串是您对 index.php 的请求。您必须将它包含在您想要从中读取它的每个请求中。

例如

$('#redactor_content').redactor({
    imageUpload: 'uploadimage.php?fname=<?php echo isset($_GET['fname']) ? htmlspecialchars($_GET['fname']) : ""; ?>',
    minHeight: 200 // pixels
});