php - moving file from webserver to application server
FIXED- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Plusnet Community
- :
- Forum
- :
- Other forums
- :
- Tech Help - Software/Hardware etc
- :
- Re: php - moving file from webserver to applicatio...
26-04-2017 4:21 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
todays conundrum.
I've come up with a PHP script that uploads a file from a web page to the webserver (and as my PHP is very rough to say the least it's probably quite brutal, but works).
the file gets uploaded to a folder on the webserver. all OK so far.
the problem is that the file needs to reside on a different server (an application server with no web services).
so i need the script to move (not copy) the file to the desired location on the application server once the initial upload had completed.
is this possible with PHP? the webserver can communicate with the application server via a domain account so comms between the two isn't a problem.
<?php include 'database.php'; $conn = sqlsrv_connect($server, $connArr); $target_server = "\\\CTECH-GLA-VWEB2"; $target_dir = "c:/speco_uploads/"; $category = $_POST["uploadcategory"]; $filedescription = $_POST["uploaddescription"]; $callRef = $_POST['ctsref']; $filestamp = $_POST['filestamp']; $loggedinuser = $_POST['ctsuser']; $target_file = $target_dir . $callRef . "_" . $category . "_" . $filestamp . "_" . basename($_FILES["fileToUpload"]["name"]); $uploaded_file = $target_server . "\\speco_uploads\\" . $callRef . "_" . $category . "_" . $filestamp . "_" . basename($_FILES["fileToUpload"]["name"]); $uploadOk = 1; $FileType = pathinfo($target_file,PATHINFO_EXTENSION); // Check if file already exists if (file_exists($target_file)) { echo "Sorry, a file with this name already exists.<br />"; $uploadOk = 0; } // Check file size if ($_FILES["fileToUpload"]["size"] > 6000000) { echo "Your file is too large.<br />"; $uploadOk = 0; } // Allow certain file formats if($FileType != "pdf" && $FileType != "PDF" && $FileType != "jpg" && $FileType != "JPG" && $FileType != "jpeg" && $FileType != "JPEG" ) { echo "Only JPG or PDF files are allowed.<br />"; $uploadOk = 0; } // Check if $uploadOk is set to 0 by an error if ($uploadOk == 0) { echo "Your file was NOT uploaded."; // if everything is ok, try to upload file } else { if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) { $query = "INSERT INTO linked_documents (LD_Link_Type, LD_Link_reference, LD_Category, LD_Description, LD_DateTime, LD_added_by, LD_Link_to_CD, LD_embedded, LD_Filename, LD_Image, LD_Document_Type, LD_Link_to_ID) VALUES ('J','$callRef','$category','$filedescription',getdate(),'$loggedinuser','CTS','0','$uploaded_file',NULL,'$FileType','0')"; $stmt = sqlsrv_query( $conn, $query ); if( $stmt === false ) { die( print_r( sqlsrv_errors(), true)); } echo "The file has been uploaded.<br /><br />"; echo "File Name : ". basename( $_FILES["fileToUpload"]["name"]). "<br />"; echo "Category : ". $category."<br />"; echo "Call Ref: ". $callRef."<br />"; echo "Uploaded By: ". $loggedinuser; } else { echo "There was an error uploading your file."; } } ?>
Fixed! Go to the fix.
Re: php - moving file from webserver to application server
26-04-2017 8:03 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
I suspect you will need to suck it and see.
I formerly had many applications that moved files via PHP FTP from PN CGI servers to PN home pages servers, and this also worked when PN CGI was replaced by PAYH. But after PN’s final move to Hostopia, outbound FTP (i.e. sessions initiated by PHP from the Hostopia side) were blocked by Hostopia’s firewall ‘for security’.
So if your PHP application runs on Hostopia’s servers but the database server is outside Hostopia altogether, everything depends on their firewall rules (i.e. ‘communication’ might work but outbound data transfer might be blocked)
Re: php - moving file from webserver to application server
26-04-2017 8:06 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
these are our own windows servers.
Re: php - moving file from webserver to application server
26-04-2017 8:40 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
Switch to pdo and prepared statements of this is going to be exposed on a public server.
Re: php - moving file from webserver to application server
26-04-2017 8:45 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
Re: php - moving file from webserver to application server
26-04-2017 9:09 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
27-04-2017 10:27 AM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
i've just realised that it can directly upload to the application server due to the IIS anonymouse access link.
so uploading to the correct location is working.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Plusnet Community
- :
- Forum
- :
- Other forums
- :
- Tech Help - Software/Hardware etc
- :
- Re: php - moving file from webserver to applicatio...