$_GET not working on my php

2019-08-31 02:01发布

I Call my PHP into my javascript code, may I know why $_GET not working in my PHP file?

My URL is : localhost/img/index.php?fname=johndoe

Javascript inside my index.php is :

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

php file 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));

    }

?>

I've used above code but when I save the file it shows blank. got nothing may I know the reason why?

1条回答
我只想做你的唯一
2楼-- · 2019-08-31 02:19

You are trying to read the data inside uploadimage.php but the query string is on your request to index.php. You have to include it in each request you want to read it from.

e.g.

$('#redactor_content').redactor({
    imageUpload: 'uploadimage.php?fname=<?php echo isset($_GET['fname']) ? htmlspecialchars($_GET['fname']) : ""; ?>',
    minHeight: 200 // pixels
});
查看更多
登录 后发表回答