Welcome Guest, Not a member yet? Register   Sign In
Access local folder from webserver php file
#1

[eluser]JasmineFlower[/eluser]
Hi

I need to access localhost directory files from webserver and store that files in to webserver folder.My php files are stored in webserver.



it is possible? pls anyone know this tell me
#2

[eluser]toopay[/eluser]
Did you mean access "local-computer's file" from "remote"(such as shared host, dedicated server, etc) server via internet, or accessing file via webserver(such as : Apache)?
#3

[eluser]JasmineFlower[/eluser]
accessing localhost file via webserver

it is possible? I have static localhost system.
#4

[eluser]JasmineFlower[/eluser]
If there is any installation need to use cURL
#5

[eluser]JasmineFlower[/eluser]
I enabled extension=php_curl.dll in php.ini file.

Code:
$dir = "../localhost folder name/";

            if (is_dir($dir))
            {
                if ($dh = opendir($dir))
                {
                    while (($file = readdir($dh)) !== false)
                    {
                        if ($file != "." && $file != "..")
                        {        
                        
                           $options = array(
                             CURLOPT_FILE => '../localhost folder name/'.$file,
                             CURLOPT_FOLLOWLOCATION => true,
                             CURLOPT_URL => 'http://example.com/foldername',
                            
                            );
                            
                            $ch = curl_init();
                            curl_setopt_array($ch, $options);
                            curl_exec($ch);
                    }
               }
          }
   }

it display below error

Code:
Warning: curl_setopt_array(): supplied argument is not a valid File-Handle resource in C:\xampp\htdocs\folder name\file.php on line 35

Is this correct code for upload file from localhost to webserver ?
#6

[eluser]JasmineFlower[/eluser]
Code:
$dir = "../localhost foldername/";
          
            if (is_dir($dir))
            {
                if ($dh = opendir($dir))
                {
                    while (($file = readdir($dh)) !== false)
                    {
                        if ($file != "." && $file != "..")
                        {        
                            
                            
                          
                         $c = curl_init();
                         curl_setopt($c, CURLOPT_URL, "http://example.com/foldername");
                      
                        curl_setopt($c, CURLOPT_USERPWD, "username:password");
                          
                        curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
                          
                        curl_setopt($c, CURLOPT_PUT, true);
                        
                        curl_setopt($c, CURLOPT_INFILESIZE, @filesize($file));
                              
                        
                              $fp = @fopen($file, "r");
                        
                              curl_setopt($c, CURLOPT_INFILE, $fp);
                          
                              
                          
                              curl_exec($c);
                          
                              
                        
                              curl_close($c);
                        
                              @fclose($fp);
                            
                        }
                    }
                    closedir($dh);
                }
            }
        }

it works only for text file but my file type is .dxf file (drawing file).cURL display the error

Code:
Warning: curl_setopt(): supplied argument is not a valid File-Handle resource
#7

[eluser]toopay[/eluser]
Have you try to use file_get_contents and file_put_contents(http://www.php.net/manual/en/function.fi...ntents.php)? cURL is to fancy for that trivial task.
#8

[eluser]JasmineFlower[/eluser]
thank u thank u it works toopay

thank u so much
#9

[eluser]toopay[/eluser]
You're so welcome and no problem at all! Just remember, if it (the task) was simple, then keep it (the method) simple!;-)




Theme © iAndrew 2016 - Forum software by © MyBB