nfinitegpu
asked on
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-da ta">
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($_FILE S['file'][ 'tmp_name' ]))
{
move_uploaded_file($_FILES ['file'][' tmp_name'] ,$uploaddi r.'/'.$_FI LES['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-fi le]: failed to open stream: HTTP wrapper does not support writeable connections. in /var/www/vhosts/miproperty .com.au/ht tpdocs/med ia/upload. php on line 14
Warning: move_uploaded_file() [function.move-uploaded-fi le]: Unable to move '/tmp/phpy9FH08' to 'http://www.remotesite.com/uploads/suka.txt' in /var/www/vhosts/miproperty .com.au/ht tpdocs/med ia/upload. php on line 14
Your file has been uploaded successfully!
i tried something like this but it didn't worked
<form action="upload.php" method="post" ENCTYPE="multipart/form-da
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($_FILE
{
move_uploaded_file($_FILES
}
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-fi
Warning: move_uploaded_file() [function.move-uploaded-fi
Your file has been uploaded successfully!
ASKER
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/
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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/
ASKER
It is possible as long as directory is writable!
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.
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.
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
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
ASKER
Ok,i will put question another way.Is there a function in PHP or ASP that allows to upload to remote directory
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
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);
ASKER
There is no ftp service running on remotehost.So that is not a solution
Is there Apache & WebDAV configured on the remote host available?
http://php-webdav.pureftpd.org/project/php-webdav
http://php-webdav.pureftpd.org/project/php-webdav
<form action="http://www.remotesite.com/upload.php" method="post" ENCTYPE="multipart/form-da
File: <input type="file" name="file" size="30">
<input type="submit" value="Upload!">
</form>
<?php
$uploaddir = "/uploads";
if(is_uploaded_file($_FILE
{
move_uploaded_file($_FILES
}
print "Your file has been uploaded successfully!";
?>