Carlvic Japitana Lim
Carlvic Japitana Lim

Reputation: 149

$_GET not working on my php

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?

Upvotes: 0

Views: 1819

Answers (1)

Quentin
Quentin

Reputation: 943207

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
});

Upvotes: 1

Related Questions