Tuesday, August 25, 2009

get current URL in PHP

$url = "http://".$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]"

Thursday, August 20, 2009

File upload PHP



<form enctype="multipart/form-data" action="uploader.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000">
Choose a file to upload: <input name="uploadedfile" type="file"><br />
<input type="submit" value="Upload File">
</form>
</pre>

<?php

$target_path = "uploads/";

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

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['uploadedfile']['name']).
" has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
}


?>

Wednesday, August 12, 2009

New line to < br >

nl2brInserts HTML line breaks before all newlines in a string


$string = "line1\n line2";

$string = nl2br($string);

output:

$string = "line1 <.br.>
line2";

Tuesday, August 11, 2009

creating directory in PHP

$target = "./files/";
$dir = "somedir";

if ( !is_dir($target.$dir) ) {
if( mkdir($target.$dir,0777,true) ) {
echo "success!";
}
}