PHP cURL - How to upload folders? -


i have simple php script scans entire directory , uploads files. want upload folders aswell. (and keep folder structure) how do that?

my code:

$dir = 'test/';  $di = new recursivedirectoryiterator($dir);  $ch = curl_init('https://website.com'); curl_setopt($ch, curlopt_url,'https://website.com'); curl_setopt($ch, curlopt_post,1);  foreach (new recursiveiteratoriterator($di) $filename => $file) {      echo $filename;     $cfile = curl_file_create($filename);     $post = array('file'=> $cfile);     curl_setopt($ch, curlopt_postfields, $post);     $result=curl_exec ($ch); }  curl_close ($ch); 

you cannot upload directory, because not information type can upload anywhere. however, there few simplest approaches.

approach 1

send directory name via curl. example:

$post = array('dir'=> $somedirectoryname); 

on other side create directory using php function mkdir

remember pass path file preserve directory structure:

$post = array('file'=> $cfile, 'path' => $somepath); 

approach 2

just pass file path file data:

$post = array('file'=> $cfile, 'path' => 'dir1/subdir2/filename.ext'); 

on other side parse 'path' , create required directories.

approach 3

create archive of directory (for example, tar.gz) , upload archive. on other side unpack archive target directory.


Comments

Popular posts from this blog

c# - Update a combobox from a presenter (MVP) -

How to understand 2 main() functions after using uftrace to profile the C++ program? -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -