download file from other server to client directly php [duplicate] - php

This question already has answers here:
Download file from FTP server directly to browser with PHP
(2 answers)
Closed 7 years ago.
my site located in server 1 and some file located in server 2. When i want to download file from server 2 to client by using ftp_get() or curl() , that function download file from server 2 to server 1 not to client.
Server 2 is a private ftp server. If that is not possible with ftp there is no solution other than ftp ?
what is the best solution to store file to server 2?

One easy way is to use Cross Domain enabled ajax to send file (post method) to another server and use below header on server 2 to accept post data from server 1.
header('Access-Control-Allow-Origin: http://server1.com');

Related

php file downloading instead of showing up on browser?

I'm running this from Filezilla remote server
anyone have any solution
<?php
echo "what a lab";
?>
For a web browser to load the output of a PHP file you need to make an HTTP request to an HTTP server which supports PHP.
FileZilla is an FTP client. It connects to FTP servers. FireZilla, if it comes into it at all, will be used only to copy the PHP file to the computer which is running both an FTP and HTTP server.
You need to enter the matching HTTP URL (e.g. http://example.com/your.php) into the address bar of your browser.

server http doesn't work while updating php file via ftp [duplicate]

This question already has answers here:
How to update a website without making it go down?
(3 answers)
Closed 3 years ago.
when I update a php file via ftp (filezilla), pages using that file stop to work until transfer is complete. The server is linux with nginx/php-fpm, but I had the same problem with apache. The only "solution" I found is to edit directly the php file on a server remote shell, and update the content. But this is a very uncomfortable solution.
Is there anybody with a better solution?
Thanks
It is normal if you are doing upload via FTP. the Best solution is using Continues Deployment services with zero downtime approach.
Continuous deployment without downtime
But if you talk about one file. You can just check php file if it exists or correct uploaded file else you can use old copy of this file.
Somesthing like this :
$file = 'uploaded.php';
$oldFile = 'uploaded_old.php';
if (file_exists($file)) {
require_once($file);
} else {
require_once($oldFile);
}

Is there a way in PHP to store printjobs that are sent via a Windows PC?

I am working on a project for school. I am wondering if there is a way in PHP to listen for print jobs and store them once received? I currently have a webserver that is accepting webhooks from other applications, parsing out the JSON and storing in a MsSQL. Is this the wrong path to take? thanks
Ok – I don’t know if this is a solution but here is my attempt at trying to help :)
Disclaimer: I am not affiliated to any of the links posted here and (or) make no recommendations.
General assumptions:
PHP is the server side language used in all instances (the theory should work with others as well – using PHP as the question was tagged as such)
Sender and receiver servers are different (it is more easier if both are on the same box – but not a show stopper)
Access to both sender and receiver webservers
Windows set up (WAMP or alternative)
You are securing your set up / directory accesses as you go along
Option 1 (Custom sender / receiver)
On the box that is sending the print request:
Create a PHP script to output the files to a temp directory
Create file with required extension (please see documentation if required)
Put contents
Close connection / file - https://www.php.net/manual/en/function.file-put-contents.php
Use powershell or alternative to put the files in the temp directory into a remote directory on the
https://blogs.msdn.microsoft.com/luisdem/2016/08/31/powershell-how-to-copy-a-local-file-to-remote-machines/
Run this at an interval of your choice
On the box that is receiving the file:
Create a PHP script to read files on remote
Show files to print in a list which can be downloaded to local terminal / device and printed
Option 2 (Leverage an existing print server)
In this option you would only need to amend the sender webserver config:
[inspired by: https://www.hashbangcode.com/article/printing-directly-php]
Download php_printer.dll for your version (https://windows.php.net/downloads/pecl/snaps/printer/0.1.0-dev/)
Enable in php.ini via: printer.default_printer=PHP_INI_ALL extension=php_printer.dll
Set the printer as your print server address and send your output to print directly from the Webserver as follows from your application:
`
$data= "Hello";
printer_set_option($ph, PRINTER_MODE, "RAW");
printer_write($ph, $data);
printer_close($ph);
}
else "Couldn't connect...";
?>'
Option 3 (Use a plugin):
https://www.neodynamic.com/products/printing/raw-data/php/

File Store in a remote server using php

I have done a project in php for a call center .
My goal is to write the call recording files in a remote server. How it possible ?.
My code is ,
if(isset($row['recAudioFile'])){
$path="http://xxxxx.com/testrecordings/";
$RecordedFile="test.mp3";
file_put_contents($path.$RecordedFile,base64_decode($row['recAudioFile']));
}
Note : I can't run any php code in the remote server Or establish a FTP Connection.

Download Remote File in PHP [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Forcing to download a file using PHP
PHP - send file to user
Is it possible to serve a file from another server , and change the name.
I have all files uploaded in another server but names are changed.I want to hit this server and fetch file from it but want to change it s name.
I wrote a simple curl script , but this adds extra traffic to my php server as well so i will be billed twice for each file and more over it will use php memory as well(if file size increases site may crash)
$init = curl_init();
curl_setopt_array($init, $opArray);
$myFile = curl_exec($init);
$info = curl_getinfo($init);
curl_close($init);
headers ....
echo File
All i am interested is in headers part but for this i need to get file into php server can this be avoided ?
You can use the following headers:
Content-Type: xxx/xxx
Content-Disposition: attachment; filename=theFilenameYouWant.xxx
If you want to avoid heavy memory consumption and if you are using Apache as web server, you can take a look at the mod_xsendfile:
http://codeutopia.net/blog/2009/03/06/sending-files-better-apache-mod_xsendfile-and-php/

Categories