Remote Server File Upload Via PHP
I have two servers, one with my website, the other for storage. I'm trying to have a page where someone can upload a file to the storage server, I'm hoping to use a form post to get it there. I've written a very simple bit of code to troubleshoot this and am having a little trouble. It works fine if I change the action to a .php that saves it on the same server, but when I change it to my storage server, it fails to upload and shows me the "else" echo that my fail failed to upload.
the HTML on my web server:
<form action="http://storageServer/upload_file.php" method="post"
enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file" />
<br />
<input type="submit" name="submit" value="Submit" />
</form>
The PHP on my storage server:
<?php
$folder = "files/";
$path = $folder . basename( $_FILES['file']['name']);
if(move_uploaded_file($_FILES['file']['tmp_name'], $path)) {
echo "The file ". basename( $_FILES['file']['name']). " has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
}
?>
The .php is in the html folder with the "files" folder.
Any reason the file isn't making it to the server that you can see?
This topic answers your question
As suggested, you could use CURL:
$ch = curl_init("http://www.remotepage.com/upload.php");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, array('fileupload' => '@'.$_FILES['theFile']['tmp_name']));
echo curl_exec($ch);
链接地址: http://www.djcxy.com/p/11128.html
上一篇: 转换为对象索引数组
下一篇: 通过PHP上传远程服务器文件