Jump to content


Photo

php, html, css


  • Please log in to reply
18 replies to this topic

#11 Kathlib the Prophet

Kathlib the Prophet

    Luck. Runs. Out.

  • Staff
  • 3,530 posts
  • Location:Undisclosed
  • Favorite Band:Metallica

Posted 24 February 2008 - 05:33 AM

It doesn't really matter where you put it, depends on how the script is structured. You can take a look at these two pages to see what I mean:

[attachment=4247:example_php_code.zip]

The admin.php page has a form that displays data from a database, which can be edited. When submitted, the data is sent to the admin_action.php page, which simply updates the database with the changed data. The script then redirects back to the admin.php page using the header() function and the admin.php page displays the contents of the database, which has been changed. However, you don't have to redirect the user from an action script, you can display HTML on that same page too, or even do both depending upon what the user has entered (but note that the header function must come before any HTML code is sent to the browser).



The key of the $_REQUEST array is what becomes of the name you gave to the form element. For example:

<input name="something" type="file">

You would then access the variable like this:

if (isset($_FILES['something'])) {

	// Stuff to do with the uploaded file

}

$_FILES is used with uploaded files, $_REQUEST is used for any other kind of data ($_POST and $_GET could also be used, but $_REQUEST takes care of both). More info about predefined variables here: http://www.phpbuilde...d.variables.php

#12 damage jackal

damage jackal
  • Staff
  • 814 posts
  • Location:Bulgaria
  • Favorite Band:Metallica

Posted 24 February 2008 - 06:14 PM

<form enctype="multipart/form-data" action="newpage.php" method="POST">

  <input type="hidden" name="MAX_FILE_SIZE" value="1048576" />

  Choose a file to upload: <input name="uploadedfile" type="file" /><br />

  <input type="submit" value="Upload File" />

</form>

<?php

 	// If a file was uploaded...

 	if (isset($_FILES['uploadedfile']) and is_uploaded_file($_FILES['uploadedfile']['tmp_name'])) {

 		// This is where the file will be placed:

 		$target_path = "uploads/";



 		/* Add the original filename to our target path. Result is "uploads/filename.extension" */

 		$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);



 		// Copy the uploaded file from the temporary directory to the place where I want it uploaded

 		if (move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path))

 	}

?>

<?php

// Update the notepad

if(isset($_REQUEST['uploadedfile'])) {

 			echo "Link to the file <a href=\"uploads/".$_FILES['uploadedfile']['name']."\">here</a>";

			echo "<br>The file <b>".  basename( $_FILES['uploadedfile']['name']). "</b> has been uploaded.";

	} else {

 			echo "There was an error uploading the file, please try again!";

	}

?>

whats wrong here?

#13 Kathlib the Prophet

Kathlib the Prophet

    Luck. Runs. Out.

  • Staff
  • 3,530 posts
  • Location:Undisclosed
  • Favorite Band:Metallica

Posted 24 February 2008 - 06:47 PM

Your action is newpage.php, so your action needs to be on that page and not the same one as your upload form--PHP is server-side, so an HTML page is what is being sent to the user, the script doesn't wait for input in the upload form and then continue.

Upload form page:

<form enctype="multipart/form-data" action="newpage.php" method="POST">

  <input type="hidden" name="MAX_FILE_SIZE" value="1048576" />

  Choose a file to upload: <input name="uploadedfile" type="file" /><br />

  <input type="submit" value="Upload File" />

</form>

newpage.php:

<?php



// If a file was uploaded...

if (isset($_FILES['uploadedfile']) and is_uploaded_file($_FILES['uploadedfile']['tmp_name'])) {



		// Add the original filename to our upload directory. Result is "uploads/filename.extension"

		$target_path = "uploads/" . basename($_FILES['uploadedfile']['name']);



		// Copy the uploaded file from the temporary directory to the place where I want it uploaded

		if (move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path))

			echo 'Link to the file <a href="uploads/' . $_FILES['uploadedfile']['name'] . '">here</a>";

			echo '<br />The file <strong>' .  basename($_FILES['uploadedfile']['name']) . '</strong> has been uploaded.';

		} else {

			echo 'There was an error uploading the file, please try again!';

		}

}



?>

Also, code is more readable if you use ' to surround code in which you need to use ", so like: echo 'This is an "example" of quotations in a string that doesn't require any backslashes.';

The new standard for <br> tags (and any other tag that is self-closing) is to use a space and a backslash: <br />

Similarly, <b> tags and <i> tags have been changed to <strong> and <em> respectively. <br>, <b>, and <i> can still be used, but it's not the preferred standard.

#14 damage jackal

damage jackal
  • Staff
  • 814 posts
  • Location:Bulgaria
  • Favorite Band:Metallica

Posted 24 February 2008 - 07:22 PM

<b> and <i> are still in the standart AFAIK http://www.w3schools...ags/default.asp
and IIRC. <br /> is for XTHML, if the user use HTML doctype <br> is ok
as for quoting, i dont know how things work in php, i found that script with google and just pasted it (with help from you)

big thanks for the input on this one, seems i dont need $_REQUEST :)

#15 damage jackal

damage jackal
  • Staff
  • 814 posts
  • Location:Bulgaria
  • Favorite Band:Metallica

Posted 06 April 2008 - 04:11 PM

in php, when am i supposed to wrap strings with ' (apostrophe)? right now i have the xml prolog wrapped:
echo '<?xml version="1.0" encoding="'. $iso[1] .'" ?' .'>';
btw, what means ' .' ?
and this not:
<?php
echo date("l, jS F Y");
?>

#16 Kathlib the Prophet

Kathlib the Prophet

    Luck. Runs. Out.

  • Staff
  • 3,530 posts
  • Location:Undisclosed
  • Favorite Band:Metallica

Posted 06 April 2008 - 06:57 PM

' and " are basically the same, but you can include one within the other. In C, ' is used for single characters, while " is used for strings, but I don't think it matters in PHP. You can also use \' and \" within a string, if you need those characters displayed. For example:

echo "He said, \"Hello world.\"";

// outputs He said, "Hello world."

The period will combine two parts, like if you have a variable and a string. For example:

$site_title = "Spawn's Bootleg Site";



echo "<p>Welcome to " . $site_title . "</p>";

// outputs <p>Welcome to Spawn's Bootleg Site</p>


#17 damage jackal

damage jackal
  • Staff
  • 814 posts
  • Location:Bulgaria
  • Favorite Band:Metallica

Posted 06 April 2008 - 07:43 PM

ok, but here: ?' .'> - there isnt var, why period was used?

my point for ' wasnt to display it ... i just want to know what is the correct way because i've seen the date for example, to be wrapped with ', " and none

#18 damage jackal

damage jackal
  • Staff
  • 814 posts
  • Location:Bulgaria
  • Favorite Band:Metallica

Posted 08 July 2008 - 06:07 PM

does anyone knows joomla? skinning in specific, there are loads selectors in css file and i dont know what is each one for :\

#19 damage jackal

damage jackal
  • Staff
  • 814 posts
  • Location:Bulgaria
  • Favorite Band:Metallica

Posted 29 December 2013 - 03:18 PM

I'm stumped on making an element's background transparent in IE8... CSS. I tried opacity, filter: alpha(), -ms-filter... nothing worked. Any ideas?


Edited by damage jackal, 29 December 2013 - 04:23 PM.
Fixed by using transparent image as background.





1 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users


    ClaudeBot (1)