Php Curl Request - uploading files


firstly - thank you for taking a look at my question.

Given the code below (which works perfectly for me). I was wondering how to do 2 things.

1 - make it so that it is a file browse rather than a hard coded file name and location.

2 - an alternate version where instead of a file - if I had a variable (for example var X = "123,4,6,7\r\n124,6,7,8") but wanted to post it as if it was a file? ie set the file name etc etc.

is it possible someone could help me with that?

$filePath = 'C:\xampp\htdocs\demo\XXXXX.csv';
// 3rd parameter is filename with extension
$cfile = new CURLFile($filePath, 'text/csv', 'XXXXX.csv');
$postFields = [
  'file' => $cfile,
  'name' => $nameofcampaign,
  'template' => $template

Open in new window

many thanks
James MurphyAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Swatantra BhargavaTechnical Specialist/DeveloperCommented:
Create a form as below and submit to your PHP page on which you are uploading the file

<!DOCTYPE html>

<form action="upload.php" method="post" enctype="multipart/form-data">
    Select File:
    <input type="file" name="fileToUpload" id="fileToUpload">
    <input type="submit" value="Upload Image" name="submit">


Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
James MurphyAuthor Commented:
thank you, your help was very much appreciated!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Development

From novice to tech pro — start learning today.