Downloading a remote server file via PHP

I have two servers, one with my site, the other for storage. I'm trying to have a page where someone can upload a file to a storage server, I hope to use a form message to get it there. I wrote very simple code to fix this problem, and I have problems. It works fine if I change the action to .php, which saves it on the same server, but when I change it to my storage server, it cannot load and will show me an โ€œelseโ€ echo that failed to load. / p>

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> 

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!"; } ?> 

.php is located in the html folder with the files folder.

Any reason the file doesn't get to the server you see?

+7
source share
1 answer

This question answers your question.

As suggested, you can try the following:

 $ch = curl_init("http://www.remotepage.com/upload.php"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CUROPT_POSTFIELDS, array('fileupload' => '@'.$_FILES['theFile' ['tmp_name'])); echo curl_exec($ch); 
+3
source

All Articles