php.ini path inside code - path

To get php.ini path i simply run
<?php
phpinfo();
?>
what is the way to get the php.ini path to show to the user. without showing the whole phpinfo file.

phpinfo(INFO_GENERAL) would be smaller
http://us3.php.net/manual/en/function.phpinfo.php

If you have PHP 5.2.4 or later, you can simply use the php_ini_loaded_file() method which returns the path as a string.
If you don't have that version, here's one way.
ob_start();
phpinfo(INFO_GENERAL);
$data = ob_get_contents();
ob_end_clean();
$lines = explode("\n", $data);
foreach($lines as $line){
list($name, $value) = explode("=>", $line);
if (trim($name) == 'Loaded Configuration File') break;
}
echo $name . ' - ' . $value."\n";
That simply prints:
Loaded Configuration File -
/etc/php5/cli/php.ini
Of course you could use a regex match or something fancier like that if you wanted to.

Related

How to check if a file is a text file?

Does Perl6 have something like the Perl5 -T file test to tell if a file is a text file?
There's nothing built in, however there is a module Data::TextOrBinary that does that.
use Data::TextOrBinary;
say is-text('/bin/bash'.IO); # False
say is-text('/usr/share/dict/words'.IO); # True
That's a heuristic that has not been translated to Perl 6. You can simply read it in UTF8 (or ASCII) to do the same:
given slurp("read-utf8.p6", enc => 'utf8') -> $f {
say "UTF8";
}
(substitute read-utf8.p6 by the name of the file you want to check)
we can make use of the File::Type with the following code.
use strict;
use warnings;
use File::Type;
my $file = '/path/to/file.ext';
my $ft = File::Type->new();
my $file_type = $ft->mime_type($file);
if ( $file_type eq 'application/octet-stream' ) {
# possibly a text file
}
elsif ( $file_type eq 'application/zip' ) {
# file is a zip archive
}
Source: https://metacpan.org/pod/File::Type

Passing URL parameter to link on page

I am trying to grab a parameter from a webpage and insert it into a URL link on that same page but am having problems with the syntax.
So, for example, the webpage is www.website.com?src=mm
Currently the code on the page that does not pull in the parameter is
<?php echo "<A HREF='http://www.website2.com?offer=AAt&sub1=422'><B>Click Here</B></A><BR>" ?>
I would like to include that "mm" parameter at the end of the URL so the final URL is:
http://www.website2.com?offer=AA&sub1=422&sub2=mm
I tried the following but does not work:
<?php echo "<B>Click Here</B><BR>" ?>
Any ideas on how to get this to work? Thanks
Your code doesn't even compile:
Parse error: syntax error, unexpected 'http' (T_STRING), expecting ',' or ';' in /var/www/html/ImagePT/test.php on line 1
it has to be
<?php echo '<B>Click Here</B><BR>'; ?>
but since I'm just in the mood to give you some further advice:
You don't have to write HTML in uppercase, it's rather unusual (not impossible, but you don't see it very often) - then this script is horrible, when the $_GET['src'] variable is undefinied, therefore I'd check if it is set and then modifiy the URL accordingly. So my advice would be to use the following:
<?php
if(isset($_GET['src']))
{
echo '<b>Click Here</b></br>';
}
else
{
echo '<b>Click Here</b></br>';
}
?>

Upload file Yii The second argument to copy() function cannot be a directory

I'm trying to upload file but get this error message :
move_uploaded_file() [<a href='function.move-uploaded-file'>function.move-uploaded-file</a>]: The second argument to copy() function cannot be a directory
I think there's something problem with this file but I've no idea to solve it..
<?php
class FileUploadController extends CController {
public function actionUpload() {
$model = new FileUpload();
$form = new CForm('application.views.fileUpload.uploadForm', $model);
if ($form->submitted('submit') && $form->validate()) {
$form->model->image = CUploadedFile::getInstance($form->model, 'image');
if($model->validate())
{
$model->image->saveAs('/opt/lampp/htdocs/upl/images');
Yii::app()->user->setFlash('success', 'File Uploaded');
$this->redirect(array('upload'));
}
}
$this->render('upload', array('form' => $form));
}
}
?>
You either need to check all files existed at '/opt/lampp/htdocs/upl/images' and check if the same named file is available or not, if available then just rename the file with extra "_1" every time, or you can always upload the file by renaming the file into some machine name sort of thing see the code below,
$name = rand(1000,9999) . time(); // rand(1000,9999) optional
$name = md5($name); //optional
$model->image->saveAs('/opt/lampp/htdocs/upl/images/' . $name . '.jpg');
This is what I usually do with file uploads, provided that you're saving the files references into the database or in any text file.
EDIT
Get Extension.
In case if you're required to get extension of the file rather then of hard-coded, you can use $model->image->getExtensionName(); it will get you the extension of the uploaded file without . (dot)
Finally, I solved it by myself:
The problem was located in line
$model->image->saveAs('/opt/lampp/htdocs/upl/images');
It should be :
$model->image->saveAs('/opt/lampp/htdocs/upl/images/images.jpg');
Now, there's another problem: when I upload 'new image', it will be replace the old file, I want the file(s) being uploaded not replaced the old file or I need something like rename as new file. Does anyone knows?
goto cuploadedfile.php .
over write this function with this
if($this->_error==UPLOAD_ERR_OK)
{
if($deleteTempFile)
return move_uploaded_file($this->_tempName,$file."/".$this->getName());
elseif(is_uploaded_file($this->_tempName))
return copy($this->_tempName, $file."/".$this->getName());
else
return false;
}
thank u.........

Is it possible to buffer the output of $app->run from silex?

I was wondering if it is possible to store the output created by silex. What I want to achieve is something like this :
<?php
require('core.php');
$out = $app->run();
echo $app['twig']->render('header.html');
echo $out;
echo $app['twig']->render('footer.html');
I'd like to do it this way because some of the navigation is build inside my dynamic controllers and registered as a global into twig. I've tried to use the out buffering ob_start mechanism without succes :
<?php
require('core.php');
ob_start();
$app->run();
$out = ob_get_contents();
ob_end_clean();
echo $app['twig']->render('header.html');
echo $out;
echo $app['twig']->render('footer.html');
Any other ideas on this subject ?
Instead of having a split of header/main/footer and using the global variables, you should use an unique template with template inheritence.
http://twig.sensiolabs.org/doc/templates.html#template-inheritance

Parse youtube feed output

Hello I am having a problem retrieving a value from this link.
So far I've been using this line of code.
$str = "https://gdata.youtube.com/feeds/api/videos/VdbUBcOCU_A";
$blow =(explode("'",$str));
print_r($blow);
And echoes out "Array" would appreciate any help how to retrieve a value from the link. Thanks.
If I am correct, you are using PHP?
Suggest you use Google PHP client library at https://developers.google.com/youtube/2.0/developers_guide_php
For your case, see https://developers.google.com/youtube/2.0/developers_guide_php#Video_Entry_Contents
$videoEntry = $yt->getVideoEntry('VdbUBcOCU_A');
printVideoEntry($videoEntry);
function printVideoEntry($videoEntry)
{
echo 'Video: ' . $videoEntry->getVideoTitle() . "\n";
echo 'Video ID: ' . $videoEntry->getVideoId() . "\n";
echo 'Updated: ' . $videoEntry->getUpdated() . "\n";
}

Resources