I have a webpage (HTML, CSS, JavaScript) hosted in a Nginx & Ubuntu & Digital OCean server. The webpage has a part where users could submit a file and call an application by PHP. I am wondering if it is possible to host this application alone in a Windows Server 2012 R2 & Microsoft Azure, which I have already.
Here is an example. This is the webpage (though the real webpage has much more contents) hosted in Ubuntu Server. The Upload the file button is linked to uploadFile.php:
<?php
copy($_FILES["file"]["tmp_name"], "uploads/" . $_FILES["file"]["name"]);
$n1 = "uploads/" . $_FILES["file"]["name"];
echo "Uploaded: " . $n1 . "<br>";
exec("mono c1.exe $n1");
...
?>
The application c1.exe is developed in C# under Windows. Because its new feature uses ode32.dll, it cannot be run with mono anymore. So I have to host c1.exe in a Windows server.
And I don't want to move the whole website to Windows server. Moreover, if possible, I want the web address in the browser address bar to be always consistent when calling php (i.e., starting with www.matrixandcompany.com/...).
Does anyone know if it is possible to realise this mechanism?
Probably you can use curl (http://php.net/manual/en/book.curl.php). You can create a php file in the server where the c1.exe is, and call it from the old server.
I would transport the file to the windows server. There are many different ways to do this.
Then call a script on the remote server which will execute the binary.
I cannot think of a different AND SECURE way.
Related
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.
can someone help me to get DESKTOP PATH?
echo "<input type='hidden' value='C:\Users\".getenv('USERNAME')."\Desktop'>";
it returns C:\Users\IT-TUPER$\Desktop
this is my desktop path C:\Users\Tuper\Desktop
In php by no means you can't have Desktop Path on a real server, as php is serverside. However if you're on localhost like xampp, wamp, or whatever on windows you try this :
<?php echo getenv("HOMEDRIVE").getenv("HOMEPATH")."\Desktop"; ?>
PHP files are in server, the client (browser) ask a petition to server (specific php file), the server render the answer, send it to client (browser).
For that reason, you canĀ“t get client path.
I had created this CMS system which uses a mySQL database and creates a file on the server.
The database side works as intended, but the creation of the file not so well.
Everything works perfectly on my localhost but the creation of the file is not working right on the external WWW server.
I had created a basic script to test the functionality of fopen() on the server. That had worked correctly, but for the real script it doesn't work.
This is the code in the real script:
if(fopen(strtolower("../News/" . $titleURL . ".php"), "w+")){
$createdPage = fopen(strtolower("../News/" . $titleURL . ".php"), "w+");
echo "page created";
}else{
echo "creation failed";
}
When this page is run, I get creation failed.
This code runs fine on the localhost, but why not on the external site?
EDIT:
My hosting service does not block fopen()
IT is very likely that the configuration for your host server (and/or the target server) does not allow any file manipulation on/by a foreign server.
Problem is resolved. I had just cleaned up the code a bit, cleaning up a lot of concatenating URLs. It appears the server did not appreciate me concatenating file locations. Everything is working fine.
I am working on a php web app .
I need to upload a file to the web server, with customer info - customers.csv.
but this process needs to be automated ,
The file will be generated in a Point of Sale app , and the app can open a browser window with the url ...
first i taught i would do something like this www.a.com/upload/&file=customers.csv
but read on here that is not possible,
then i taught i would set a value for the file upload field and submit form automatically after x seconds. Discovered thats not possible .
Anybody with a solution , will be appreciated .
EDIT
I have tried this and it works ,file is uploaded to remote server
is it working only because the php script is running on the same pc where csv is sitting ???
$file = 'c:\downloads\customers.csv';
$remote_file = 'customers.csv';
// set up basic connection
$conn_id = ftp_connect('host.com');
// login with username and password
$login_result = ftp_login($conn_id,'user','password');
// upload a file
if (ftp_put($conn_id, $remote_file, $file, FTP_ASCII)) {
echo "successfully uploaded $file\n";
} else {
echo "There was a problem while uploading $file\n";
}
// close the connection
ftp_close($conn_id);
This is of course not possible, imagine how this could be abused to upload on linux as example the /etc/passwd. The only way it might be possible is to use a Java Applet, but this is for sure not the best way.
You could try to let your PoS Application make a web request with the customers.csv file and let a WebAPI handle the upload, this may be possible, but I have no expierence with Point of Sale Applications.
Best might be, if the solution above cannot be considered, to just prompt the user to provide the file above and check over name + content if it is the correct one.
This is a bit tricky, but if your CSV is not too long, you could encode it in base64, send to the webserver as a GET parameter and then, in the server side, decode and store it as a CSV file.
If the file is too big to do that, you have to use other method, like the java applet pointed by #D.Schalla or even install and configure a FTP server, and make the Point of Sale app uploads the file there.
Other alternative, specially good if you cannot modify the sale app, is to install a web server in the client side and write a small php script to handle the upload process. In this way, the sale app could call a local url (something like: http:// localhost/upload.php) and it's this script the one in charge to upload the file which can be achieve with a classical HTTP POST, a FTP connection or any other way you can think about.
MY Solution , which will work with out setting up web server on client side.
This is for windows but can be adapted to linux
On client side
Local Application opens cmd and runs this command ftp -n -s:C:\test.scr
WHICH opens test.scr - a file with ftp commands e.g.
open host.com
user1
passwOrd
put C:\downloads\customers.csv public_html/customers.csv
more info here :
http://support.microsoft.com/kb/96269
more commands :
http://www.nsftools.com/tips/MSFTP.htm#put
how to test if a file exist on the current computer using the application ?
I try to put the full url at my file like this, but it doesn't work :
if(file_exists("C:/wamp/www/project/photo/".$nom_photo))
{
echo "file exist";
$extension=pathinfo("C:/wamp/www/project/photo/".$nom_photo,PATHINFO_EXTENSION);
echo "<br>";
$nom=md5($nom_photo.time().rand(0, 99999)).".".$extension;
echo $nom;
rename("C:/wamp/www/project/photo/".$nom_photo,"C:/wamp/www/project/photo/".$nom);
echo "<br>";
}
How to fix it ?
PHP operates server side and has NO ACCESS to the files on the machine running the web browser, unless they are indeed the same machine.
If you are meaning to find a way to test if a file exists on the web server, the file_exists() function you mentioned should find it. There are many reasons this might fail, including safe_mode, file permissions, and using the wrong path.
The server doesn't have any access to the clients filesystem, this would be a major security flaw.
Also javascript is sandboxed so you couldn't do it on the client side either.
The only way I can think of doing this is to get the user to download a separate application that looks for the file and reports back to the server.