How do I use php rename across servers - php

I need to move a file from one server to another using PHP. What is the proper syntax for this? Everything I have tried has failed, yet I know permissions are correct. I believe it should be something like:
rename('//server1.host.com/folder/file.txt','//server2.host.com/folder/file.txt');
I am trying this on Windows 2012 servers and have access to everything.
The web server running this code currently has the file on it, I'm trying to move the file to another host.

Related

How do you manage your PHP and SQL file once uploaded to a server?

First of all I apologize for the dumb question. I'm new with all this. I already searched an answer on Google, but I couldn't find anything comprehensible for me.
So, I managed to create my html, CSS, JavaScript files. I managed to install XAMPP, create SQL databases, access and update them with PHP from my html page.
Now I have full access to my files, since they're on my computer. But how does it work when I move them to a server?
First, what files should I move exactly? All the XAMPP folder? Just html, css, js and PHP?
Second, once uploaded the files, how can I access them, for updating, or for viewing the database? Can I still use XAMPP or after uploading the files to a server XAMPP becomes useless?
Thank you a lot.
First of all if you want to upload file to a online server. there are many tools which can allow you upload them. In my Case i use filezila.
This is how it is presented:
you will move everything located under xamp/htdocs/YOUR_PROJECT and move it on the server ( in my case under public_html folder). Html, php, css, ...
You can delete, rename or modify them within filezila at server file section as described in the picture. Right click on a file > all actions will be seen
for viewing the database check in Admin panet of your host website in my case hostinger and on Databases choose for example phpmyadmin and you will be redirected to you Database panel to view all your databases
I think this helped.
Your hosting provider presumably already has the equivalent of your XAMPP stack installed. (Unless you're starting with an unmanaged VPserver, in which case you'll have to install and configure an Apache-MySQL-PHP stack before your website will function.) Assuming a standard hosting solution, you will only need to upload the files specific to your project.
Basic steps to deploy from local to remote server:
Using an FTP client of your choice, upload your PHP, HTML, CSS, JS, image etc. files to your server's public_html folder. (Full path will be something like /home/example.com/public_html/ on a Linux server, depending on your hosting provider.)
Use a database manager (such as PHPMyAdmin) to upload the SQL file into a database you've created.
Update any absolute paths you may have used in your PHP files, reflecting the live/production server's filesystem structure.
Update your database-connecting PHP file(s) with the appropriate credentials. (They're probably different from your local server's user/password.)
You will want to ensure that your remote server's configuration supports all the functionality your code depends on (e.g. PHP modules and other configuration).
If you put a bit of thought into your code, you won't have to maintain separate local/remote files, and won't have to bother with steps 3 & 4. You can e.g. define your configuration based on a local IP address check (we're testing for both IPv4/6), as follows:
if (in_array($_SERVER['REMOTE_ADDR'], ['127.0.0.1', '::1'])) {
// local config here
} else {
// remote config here
}
Then, does your local server become useless? If you don't ever intend to develop code again -- yes. Otherwise, you will probably want to develop and test your code on your local machine, and only deploy it to your live/production server when you're satisfied it's stable enough for public release. You don't want to do your R&D on the live server!

Using PHP scripts from html on mac's default web server

I'm developing a site with PHP and I need to test it using my Web Server on Mac. I installed the server and made sure it's working. Localhost is seeing and serving whatever I put in /Library/WebServer/Documents.
Now I put a test script in the CGI-Executables directory, and tried calling it from an html file inside the Documents directory. It results in this error:
The requested URL /CGI-Executables/SM.php was not found on this server.
The file is there, so I'm assuming it's a configuration issue, and looking around I played with the /etc/apache2/extra/httpd-vhosts.conf file but it seems like an overkill. I don't need a virtual host, and I'm not going to serve anything from my development machine. I just want to develop my site.
You should either put your scripts in /Library/WebServer/Documents/ or call them like /cgi-bin/SM.php Also, are you sure you want cgi scripts or do you just need your php to work? If its the latter, then putting them up in the Document root is a better option than using it as cgi script.

php - Script Not Working After Being Uploaded To Live Server

I am developing a php script locally using XAMPP, it is working on my local server, but after being uploaded to the linux live server, there are many things those won't work. Most of the problems are caused by file path writing.
For example:
require('inc/config.php') working in XAMPP but it does not work on live server or vice versa. So I need to change it to require('config.php') in order to make it able to be called on live server.
That seem like ruining the whole of my works and make the times I invested become useless.
My question:
What's the common solution can I use to prevent that kind of problem? Is using full path to call a file the best practice?
Is there any local development environment for Windows like XAMPP that able to simulate linux server structure, so there will be nothing need to be fixed after finishing development on local server then upload it to linux live server?
Please somebody help..
Best Regards
You don't need to change anything, just in the index.php give your script proper path to your scripts using set_include_path().

PHP FTP fwrite() to Windows server not working?

I am attempting to fwrite() via an FTP wrapper from a UNIX-based server to a Windows-based server with PHP. I am connecting successfully, and am able to (for example) create directories. However, I can't seem to write files to the folders! When I look at the directory permissions using an FTP client, I noticed that they are all 0000, and cannot be changed. Apparently, Windows-based servers do not use the same FTP permission system.
So... what's up? What do you recommend? I am able to upload files to the directory using an FTP client, but when I attempt to write files with PHP, nothing happens.
I am at a complete loss as to why this may be occurring. I have confirmed my script works by writing to UNIX-based servers, so that is not a problem. Is it possible that the fact the destination server does not have PHP installed matters? I would not think so, but I'm open to any ideas at this point!
Thank you!
EDIT - What's really getting me is that I AM able to create directories, so it doesn't make any sense that writing shouldn't be working. On Windows servers, is there some setting that would prevent just the writing of FILES, but not folders?
EDIT 2 - More research has told me that, though you cannot CHMOD on Windows servers, PHP's CHMOD still somehow does something with the permissions. However, this does not appear to be working for me. Is there a way to change the permissions directly with PHP code, or is this something that has to be done directly on the server, outside of my reach?
I recommend file_put_contents, and make sure PHP is allowed to write in that directory.

How do I run a file on localhost?

How do I actually run a file on localhost?
I know it is working, but how do I run a file on it, and how do I verify that the file is in fact running on localhost?
Server newbie here, additional questions (I have xampp running Apache 2.2):
From your responses it sounds like I have to type in the path in the browser in order to open the file on the localhost. So, if I want to have the file in a subdirectory, I would have to type the full path including the directory?
Is there a way to have the browser point to the localhost while I am working on my html, instead of having to type in the path all the time?
I am working in Dreamweaver CS3, and want to use include commands (either SSI or PHP), but not have to keep putting my files up on HostGator in order to see if they are working.
What is the best way to do this (please be specific, I know nothing). If there is a detailed tutorial anywhere, really appreciate a link.
Thank you
Ok, thanks for the more specific info, ppl may remove their downvotes now...
What you are proposing is a very common thing to do! You want to run your web application locally without uploading it to your host yet. That's totally fine and that's what your Apache is there for. Your Apache is a web server meaning its main purpose is to serve HTML, PHP, ASP, etc. files. Some like PHP; it first sends to the interpreter and then sends the rendered file to the browser. All in all: it's just serving pages to your browser (the client).
Your web server has a root directory which is wwwroot (IIS) or htdocs (apache, xampp) or something else like public_html, www or html, etc. It depends on your OS and web server.
Now if you type http://localhost into your browser, your browser will be directed to this webroot and the server will serve any index.html, index.php, etc. it can find there (in a customizable order).
If you have a project called "mytutorial" you can enter http://localhost/mytutorial and the server will show you the index-file of your tutorial, etc. If you look at the absolute path of this tutorial folder then it's just a subfolder of your webroot, which is itself located somewhere on your harddrive, but that doesn't matter for your localhost.
So the relative path is
http://localhost/mytutorial
while the absolute path may be
c:/webservices/apache/www
or
c:/xampp/htdocs
If you're working with Dreamweaver you can simplify the testing process by setting up your local server as a testing server in your project settings. Try it! It's easy. Once it's done, you can just press the browser icon with any of your files and it will open on localhost.
You can do it by running with following command.
php -S localhost:8888
I'm not really sure what you mean, so I'll start simply:
If the file you're trying to "run" is static content, like HTML or even Javascript, you don't need to run it on "localhost"... you should just be able to open it from wherever it is on your machine in your browser.
If it is a piece of server-side code (ASP[.NET], php, whatever else, uou need to be running either a web server, or if you're using Visual Studio, start the development server for your application (F5 to debug, or CTRL+F5 to start without debugging).
If you're using a web server, you'll need to have a web site configured with the home directory set to the directory the file is in (or, just put the file in whatever home directory is configured).
If you're using Visual Studio, the file just needs to be in your project.
Localhost is the computer you're using right now. You run things by typing commands at the command prompt and pressing Enter. If you're asking how to run things from your programming environment, then the answer depends on which environment you're using. Most languages have commands with names like system or exec for running external programs. You need to be more specific about what you're actually looking to do, and what obstacles you've encountered while trying to achieve it.
Looking at your other question I assume you are trying to run a php or asp file or something on your webserver and this is your first attempt in webdesign.
Once you have installed php correctly (which you probably did when you got XAMPP) just place whatever file you want under your localhost (/www/var/html perhaps?) and it should run. You can check this of course at localhost/file.php in your browser.
Think of it this way.
Anything that you type after localhost/ is the path inside the root directory of your server(www or htdocs).
You don't need to specify the complete path of the file you want to run but just the path after the root folder because putting localhost/ takes you inside the root folder itself.
i am working in VScode currently. i was wanting to run my html page just to see all my main elements.
1) first, in vs, right click desired html file and choose "copy path". do not choose relative.
2) finally, paste html path in address bar (i used chrome) and hit enter. your html page should display. hope this helps someone out.

Categories