Php Curl Request - uploading files

James Murphy
James Murphy used Ask the Experts™
on
Hi,

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?

<?php
$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
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Technical Specialist/Developer
Commented:
Create a form as below and submit to your PHP page on which you are uploading the file

<!DOCTYPE html>
<html>
<body>

<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">
</form>

</body>
</html>

Open in new window

Author

Commented:
thank you, your help was very much appreciated!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial