1

I have one url,from there I am passing one parameter two values,Now my question is,I want take the values push in to array how can do this?

MY URL

http://localhost/TransitoakAdmin/licenseUpload.php?uploadfile=file1.docx&file2.pdf

I want make like this

$fileNames=array('files/file1.docx','files/file2.pdf');

2 Answers 2

1

Please check following code ;

$url = "http://localhost/TransitoakAdmin/licenseUpload.php?uploadfile=file1.docx&file2.pdf";
$urlstrip = explode('uploadfile=',$url);
$fileNames = explode('&',$urlstrip[1]);

foreach ( $fileNames as $key=> $fileName ){
    $fileNames[$key] = 'file/'.$fileName;
}

var_dump($fileNames);
Sign up to request clarification or add additional context in comments.

Comments

1

Use $_GET to retrieve values from URL parameters and explode to split a string by string.

website.com/uploadFile=file1.docx,file2.docx

$param = htmlspecialchars($_GET['uploadFile']);
$files = explode(',', $param); // outputs ['file1.docx', 'file2.docx']

array_map(function($val) {
    return 'files/' . $val; // prepend 'files/' string to each entry
}, $files);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.