Is there a way to upload a file to a "File" field using either a direct upload ("Browse" button) or a URL input? I noticed that the built-in file field only support direct upload.
ExpressionEngine® Answers is a question and answer site for administrators, end users, developers and designers for ExpressionEngine® CMS. It only takes a minute to sign up.Sign up to join this community
Yes, the built-in file field only support direct upload. For a URL input upload, you will need to develop a custom field type. It's possible with the cURL of PHP. Here I can share PHP code example how a remote file can be saved within a directory.
$upload_dir_path = '/UPLOAD/DIRECTORY/PATH/'; $file_url = 'URL OF THE FILE'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $file_url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1); curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2); curl_setopt($ch, CURLOPT_TIMEOUT, 60); $upload_file = curl_exec($ch); file_put_contents($upload_dir_path, $upload_file);
I hope, you would be aware to develop an EE field type and above code example would be helpful for you.