• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 698
  • Last Modified:

How to upload to remote directory

I'm trying to create a php script that will upload to remote server and remote directory

i tried something like this but it didn't worked

<form action="upload.php" method="post" ENCTYPE="multipart/form-data">
File: <input type="file" name="file" size="30">
<input type="submit" value="Upload!">
</form>


<?php

$uploaddir = "http://www.remotesite.com/uploads";
if(is_uploaded_file($_FILES['file']['tmp_name']))

{

move_uploaded_file($_FILES['file']['tmp_name'],$uploaddir.'/'.$_FILES['file']['name']);

}

print "Your file has been uploaded successfully!";

?>

I get following error

Warning: move_uploaded_file(http://www.remotesite.com/uploads/suka.txt) [function.move-uploaded-file]: failed to open stream: HTTP wrapper does not support writeable connections. in /var/www/vhosts/miproperty.com.au/httpdocs/media/upload.php on line 14

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpy9FH08' to 'http://www.remotesite.com/uploads/suka.txt' in /var/www/vhosts/miproperty.com.au/httpdocs/media/upload.php on line 14
Your file has been uploaded successfully!
0
nfinitegpu
Asked:
nfinitegpu
  • 5
  • 3
  • 2
  • +1
1 Solution
 
babuno5Commented:
your code should look some thing like this to work


<form action="http://www.remotesite.com/upload.php" method="post" ENCTYPE="multipart/form-data">
File: <input type="file" name="file" size="30">
<input type="submit" value="Upload!">
</form>


<?php

$uploaddir = "/uploads";
if(is_uploaded_file($_FILES['file']['tmp_name']))

{

move_uploaded_file($_FILES['file']['tmp_name'],$uploaddir.'/'.$_FILES['file']['name']);

}

print "Your file has been uploaded successfully!";

?>
0
 
nfinitegpuAuthor Commented:
No no you didn't get my point.The upload file is on http://www.localserver.com/upload.php and writable directory is on http://www.remotesite.com/uploads/
0
 
babuno5Commented:
Then what you are trying to achieve is not possible

the possible ways is to upload first to local and then make a ftp or ssh transfer from local to remote
Access to  remote will be require for the same
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
nfinitegpuAuthor Commented:
No no you didn't get my point.The upload file is on http://www.localserver.com/upload.php and writable directory is on http://www.remotesite.com/uploads/
0
 
nfinitegpuAuthor Commented:
It is possible as long as directory is writable!
0
 
AielloJCommented:
nfinitegpu:

babuno5 is correct.  If anyone was able to directly upload to another site/domain it would open up all kinds of security issues.  Babuno5's suggestion to upload it then FTP it is the way.  That's also part of the reason that all uploads go to a temp directory on your server and have to be explicitly moved to the final folder.
0
 
Michael WorshamInfrastructure / Solutions ArchitectCommented:
From what it sounds like, you want to use a local php script on one site to upload content to another site. Under basic PHP guidelines, this won't be happening as EE Export babuno5 stated, as you cannot just point an move_uploaded_file() function to a remote site. That's not how this function works.

Reference:
http://www.php.net/move_uploaded_file
http://forums.devshed.com/php-development-5/move-uploaded-file-to-remote-server-441823.html
http://www.phpbuilder.com/board/archive/index.php/t-10318628.html
0
 
nfinitegpuAuthor Commented:
Ok,i will put question another way.Is there a function in PHP or ASP that allows to upload to remote directory
0
 
Michael WorshamInfrastructure / Solutions ArchitectCommented:
There isn't a function directly that can upload to a remote site. You are going to have to build out the PHP functionality in a way similar to the snippet I have provided below.

Reference:
http://phpsense.com/php/php-ftp-functions.html
http://us2.php.net/manual/en/ftp.examples-basic.php

$connection = ftp_connect($server);
$login = ftp_login($connection, $ftp_user_name, $ftp_user_pass);
 
   if (!$connection || !$login) { 
       die('Connection attempt failed!'); 
   }
   $upload = ftp_put($connection, $dest, $source, $mode);
   if (!$upload) { 
      echo 'FTP upload failed!'; 
   }
 
ftp_close($connection); 

Open in new window

0
 
nfinitegpuAuthor Commented:
There is no ftp service running on remotehost.So that is not a solution
0
 
Michael WorshamInfrastructure / Solutions ArchitectCommented:
Is there Apache & WebDAV configured on the remote host available?

http://php-webdav.pureftpd.org/project/php-webdav
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 5
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now