Page 1 of 1
php file upload
Posted: Mon Apr 11, 2016 1:21 am
by gorachand
I am a newbie to the world of webdesign and my experience is one website old.I am reading the basic text books on php and viewing the tutorial videos on YouTube and have the following question.
The textbook advises me to code php along with html and save it as index.php and “ put it onto your php enabled server”—On which folder on the server am I supposed to upload my index.php file to.There is also an index.html file which contains the same html code excepting the php part which I have uploaded to public_ html folder on the server.
When it comes to running the webpage which of these two files will have precedence-?
Can anyone explain my problem?
Regards,
Sourav
Re: php file upload
Posted: Mon Apr 11, 2016 4:27 am
by requinix
Depends on the server configuration. Try it and find out? But you could always go to /index.html or /index.php explicitly.
It's inadvisable to have multiple files like that, though. Can get confusing. And if you move servers then you could easily find the wrong files being executed.
Re: php file upload
Posted: Mon Apr 11, 2016 9:22 am
by gorachand
Hello,
Thank you for your reply.Could you please answer t hree more questions?
Question 1)
I write a page of html with php script inserted on the page in the appropriate place.For the php code to execute should the page file be saved with extension php or html?
Question 2)
I hear that php code while executing generates and sends created html to the browser.So if I open a php codes page in a browser and go to file- show source code- the html code that will show up- will it be equal to my original html code or will include the php created html? I take it that the php script which I had coded in my original file ( the one I uploaded to the server)will not show up.Correct? Yes or no?
Question 3)
At least one php tutorial on YouTube says that to write MySql code one clicks on the php.admin link on the server control panel and enters the code there.Can php code also be entered in the same way as one of the ways of uploading php to the server?
Waiting to hear from you
Regards,
Sourav
Re: php file upload
Posted: Mon Apr 11, 2016 3:19 pm
by Christopher
1. The extension should be .php
2. If you show source in the browser of a PHP file it will display any text you have outside of <?php ?> tags, PLUS any text that the PHP code outputs with echo, print, etc. A PHP script does not have to generate output. Typically programmers separate the PHP code that outputs to the browser into template files. The rest of the code is put in classes, each in its own file to be autoloaded.
3. One way to test SQL code is to enter it into an app like php.admin and execute it. SQL code can also be executed within PHP code using the PDO or Mysqli database libraries (See the PHP manual for examples).
Re: php file upload
Posted: Mon Apr 11, 2016 5:58 pm
by requinix
3. That tutorial is talking about testing your SQL. I assume? You do that to make sure your queries are working, then you put them into your PHP code. It's not like you're using the admin thing to "save" the SQL to the server. So no, you wouldn't do something like that with PHP, and you would put code into files and upload them to the server (after you've tested everything, of course).
Re: php file upload
Posted: Mon Apr 11, 2016 10:57 pm
by Christopher
More 3. The think that using an admin tool to execute your SQL will do is show you any error message you get. Some also check the SQL syntax. You can also have your PHP code check and print error messages from the database with code like this:
Code: Select all
if ($mysqli->errno) {
echo "ERROR: {$mysqli->error}<br>";
}
Re: php file upload
Posted: Tue Apr 12, 2016 1:44 am
by gorachand
Hello,
Thank you for your reply.
1.)One of the ways that php outputs to the browser is through the echo or print command.Once that command executes text appears on the browser.Is there any function by which html tags ( not text) can be outputted to the browser?
2.)As you said—text can be outputted to the browser by the echo function.How can I have control as to where the text appears in the browser display?Also –when the echo command outputs text to the browser---- are html tags also outputted to the browser or only a line of text?
Waiting to hear from you
Regards,
Sourav
Re: php file upload
Posted: Tue Apr 12, 2016 6:26 am
by Celauran
HTML tags are text, so you can echo them. Better still, you can display output anywhere inside the template, so you can easily do something like this:
Code: Select all
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Some Title Here</title>
</head>
<body>
<div class="foo">
<div class="bar">
<div class="baz">Today's date is: <?php echo date('Y-m-d'); ?></div>
</div>
</div>
</body>
</html>
You have complete control over what gets displayed where.
Re: php file upload
Posted: Tue Apr 12, 2016 12:13 pm
by gorachand
Hello,
Thank you for your reply.
Whenever the browser sends a request to the web server the server software searches for a file index.html which is the home page of the requested site.Supposing I code my homepage with html and php and save it as index.php—will it perform as my home page file?
Then I suppose there is no need for creating and saving a page—index.html for my homepage?
Waiting to hear from you
Regards,
Sourav
Re: php file upload
Posted: Tue Apr 12, 2016 12:22 pm
by Celauran
You can configure which files the web server treats as the document root as well as their order of precedence.
Re: php file upload
Posted: Tue Apr 12, 2016 4:49 pm
by Christopher
Many web hosts have a default configuration to server either index.php or index.html as the default page -- try it and see.
Also, to clarify why we said the output was "text" instead of "HTML". PHP can output any kind of text (or data). HTML is the most common text that is output, but web apps also often genreate XML or JSON. And you can create output for many file types like PDF, CSV data / Excel spreadsheets, RTF Word documents, etc. Those will be downloaded by the browser.