简体   繁体   中英

How to pass various parameters in URL using POST method in PHP

I have written some php code for uploading files in a php. When I submit the code, it's working fine, now I need that filename in URL. I know it can be done using the GET method, but is there any method to do all this using the post method?

$fname = $_POST['profile']['name'];
$url_page = "http://localhost/File_Upload/index.php";
$id = "43434343";
$url = rawurlencode($url_page);
$url .= "?file_name=" . urlencode($fname);
$url .= "&id=" . urlencode($id);
echo htmlspecialchars($url);

I have used the above code, but how it can be used to pass parameters in URL?

Thank you in advance!

You can use base64 encoded url in your form as a hidden field base64_encode() like

<input type="hidden" value="<?php echo base64_encode($url);?>" name="url" />

Now you need to decode it on form submit code.

If your id and filename are dynamic then you can use $.ajax() and update your url from AJAX success callback dynamically like on change event of file name.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM