register_argc_argv can't be set via ini_set - php-ini

i have following problem...
i have a webapplication and i want to use
register_argc_argv
in my php.ini it is turned off
Directive Local Value Master Value
register_argc_argv Off Off
now the problem is, i can't access the php.ini file directly because its on a hosted sever.
and actually even if i could, i don't want to turn on the master value.
in my index.php the first rows are:
<?php
# Config
require_once( "php/config.php" );
// some more of my source
?>
in the config.php my source starts like this:
<?php
ini_set( "register_argc_argv", "1" );
ini_set( "display_errors", "1" );
ini_set( "display_startup_errors", "1" );
// some more of my source
?>
but it won't turn on.
Question:
Am i doing something wrong ?
Is there a solution for this?
Could this be blocked by provider ?
What i have tried:
ini_set( "register_argc_argv", "1" );
ini_set( "register_argc_argv", 1 );
ini_set( "register_argc_argv", "On" );
ini_set( "register_argc_argv", true );
And no PHP: How to override register_argc_argv? is not a dublicate because
this answere doesn't work for me
you see my first line and there is nothing executed befor

Related

I have a warning on all of my posts on my page after I updated my theme

I have just updated my theme and the following error occurs:
Warning: sprintf(): Too few arguments in /home/itsallab/public_html/wp-content/themes/covernews/lib/breadcrumb-trail/inc/breadcrumbs.php on line 254
On this line of the file it writes :
:sprintf('%s', $item );
What part could cause this error?
i found the resolution. it had two '' more that needed in here "'.esc_url( $link_item ).'"
dont know why after the update it changed but i
String concatenation and sprintf should not been combined in a single line. Try using the following:
sprintf('%s', esc_url( $link_item ), $item );

I only want to print the table names from my DB

Here is my code. I get an internal server error with this. The subroutine is a clone from a book. So it is good to go. I just cannot get these tables to be on the screen by the time I look at the site. Is there anything that you guys see I am doing wrong?
#!/usr/bin/perl -T
use 5.010;
use DBI; #this is for database connections.
use CGI qw/:standard/;
use CGI::Carp qw(fatalsToBrowser);
#my $driver = "mysql";
my $database = "myown";
my $hostname = "whereitis";
my $dsn = "longblabla";
my $userid = "memyselfandI";
my $password = "onlymetoknow";
my $page1 = "Tables in the database: " . $database;
my $dbh = DBI->connect( $dsn, $userid, $password ) or die $DBI::errstr;
print
header,
start_html(
-title => $page1,
-meta => {
'viewport' => 'width=device-width, initial-scale=1',
'copyright' => 'copyright 2015 Noel Villaman'
},
-style => [
{ -src => 'bootstrap.min.css' },
{ -src => 'cgicssjs/style1.css' }
]
),
h1( $page1 ),
div( table_names( $dbh->table_info() ) ),
hr,
"\n";
# Disconnect from the database.
$dbh->disconnect();
print end_html;
sub table_names {
my $names = $_[0];
### Create a new statement handle to fetch table information
my $tabsth = $names; #$dbh->table_info();
### Print the header
print "<h1>Table Name</h1>";
print "<h3>===============</h3>";
### Iterate through all the tables...
while ( my ( $qual, $owner, $name, $type, $remarks ) = $tabsth->fetchrow_array() ) {
### Tidy up NULL fields
foreach ( $qual, $owner, $name, $type, $remarks ) {
$_ = "N/A" unless defined $_;
}
### Print out the table metadata...
print "<h3>$name</h3>";
}
exit;
}
In a comment, you say that you don't think that you can see the web server error log. It is ridiculous to try to develop a CGI program without access to the server error log. You should try to get that fixed as a matter of urgency.
But in the mean time, you can work round this restriction by adding the following near the top of your code.
use CGI::Carp 'fatalsToBrowser';
That will copy the error log messages to your browser so you can see them. But remember to remove or comment out that line before the code goes into production (not that this code will ever go into production in any meaningful way - I realise it's homework).
While you're editing that part of your code, also add:
use strict;
use warnings;
You should add these lines to every Perl program you write and fix all the errors and warnings that they give you.
So what's the problem with this code? I suspect that running it from the browser, you'll get an error about there being no CGI header line. That's because you exit() the program from the end of your table_names() subroutine. So the program never gets back from calling the table_names() subroutine and your main print() statement never gets executed - and that includes the header().
Also, in your main print() statement, you print the value returned from table_names(). But table_names() doesn't return anything. You need to change the logic in table_names() so that it returns the HTML it creates rather than printing it directly. Printing it directly will put it in the wrong place in the output stream.
One other point that I don't expect you're in any position to do anything about... CGI is pretty much a dead technology. This course is teaching you stuff that would have been useful fifteen years ago. Perhaps you could point your teacher at CGI::Alternatives and ask if he or she would consider teaching something that is more relevant to how web development is done today.
Update: The simplest fix is probably to split up your print statement so that things happen in the right order.
# Print all the start page stuff
print
header,
start_html(
-title => $page1,
-meta => {
'viewport' => 'width=device-width, initial-scale=1',
'copyright' => 'copyright 2015 Noel Villaman'
},
-style => [
{ -src => 'bootstrap.min.css' },
{ -src => 'cgicssjs/style1.css' }
]
),
h1( $page1 );
# No need to call print here as table_names
# does its own printing
table_names( $dbh->table_info() );
# Print all the end of page stuff.
print
hr,
"\n";
You'll still need to remove the exit() from the end of table_names, otherwise the program will never return from that subroutine.
Also, by doing this you lose a <div> around the output from table_names. Fixing that is left as an exercise for the reader.

I want to save a image file to server folder and save its path to mysql

The problem is that the image is not moved to UPLOAD_DIR path, but the path of that file is successfully inserted in server.
<?php
$con=require_once("connection.php");
define('UPLOAD_DIR', 'http://hpms.hostei.com/images/');
$image= $_REQUEST['image']; //byte image data received
$image = str_replace('data:image/png;base64,', '', $image);
$image = str_replace(' ', '+', $image);
$data = base64_decode($image);
$file = UPLOAD_DIR . uniqid() . '.png';
$success = file_put_contents($file, $data);//
print $success ? $file : 'Unable to save the file.';
$code=0;
if($r=mysql_query("insert into images values('','$file')"))
{
$code=1;
}
print(json_encode($code));
mysql_close();
?>
Hi awais khan sar,
You can use the $_FILES server variable. $_REQUEST is used for GET and POST both method
but you are uploading images i have also this problem and solved with this type. you can
create post method from any mobile device then save it into folder using
move_uploaded_file() if any query then tell me, Thanks Hiren kubavat.

How can I call a console command in web application in Yii 2.0

I have a console command to generate user report. I want to call the same from my web application. I am using Yii 2.0.0 beta version.I tried to follow answers given in this post How to call a console command in web application action in Yii?
Since Yii 2.0 structure is very different from Yii 1.1 ,I get errors if I try to include command/userReportController.php .Can someone guide me on this?
You should use an extension like https://github.com/vova07/yii2-console-runner-extension
I think this is the simplest solution:
$controller = new YourConsoleController(Yii::$app->controller->id, Yii::$app);
$controller->actionYourConsoleAction();
use this code:
$application = new yii\console\Application($config);
$application->runAction('controller/action');
I'm using this method instead of yii console command, because I'm running Yii on managed VPS where unix commands are not supported in cron, only php scripts.
To run it this way instead of console, the yii configuration must be initialized first, of course:
defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'dev');
require(__DIR__ . '/vendor/autoload.php');
require(__DIR__ . '/vendor/yiisoft/yii2/Yii.php');
require(__DIR__ . '/common/config/bootstrap.php');
require(__DIR__ . '/console/config/bootstrap.php');
$config = yii\helpers\ArrayHelper::merge(
require(__DIR__ . '/common/config/main.php'),
require(__DIR__ . '/common/config/main-local.php'),
require(__DIR__ . '/console/config/main.php'),
require(__DIR__ . '/console/config/main-local.php')
);
Let's say your action is called file/convert, and you want to run it in the background:
$cmd = "cd /home/site.com/public_html/yii && nohup php yii file/convert >/dev/null &";
shell_exec( $cmd );
yii2-console-runner-extension keeps loading.
Try this:
It's yii (without ext, not yii.bat)
Make sure that php folder added to PATH variable (Windows)
$op = shell_exec ( 'absolute/path/to/yii ' . 'cache/flush-all' );
\yii\helpers\VarDumper::dump($op, 10, 1);
Output:
The following cache components were processed:
* cache (yii\\caching\\FileCache)
If you really want to run Console controller by Web controller likes migrate:
public function actionMigrate()
{
// Keep current application
$oldApp = \Yii::$app;
// Load Console Application config
$config = require \Yii::getAlias('#app'). '/config/console.php';
new \yii\console\Application($config);
$result = \Yii::$app->runAction('migrate', ['migrationPath' => '#app/migrations/', 'interactive' => false]);
// Revert application
\Yii::$app = $oldApp;
return;
}
Above sample code is for yii2-app-basic template, you could change path for yii2-app-advanced template.

Why is this Perl CGI script failing to upload images correctly?

I have this code:
use CGI;
use File::Basename;
use Image::Magick;
use Time::HiRes qw(gettimeofday);
my $query = new CGI;
my $upload_dir = "../images"; #location on our server
my $filename=$query->param("img");
my $timestamp = int (gettimeofday * 1000);
my ( $name, $path, $extension ) = fileparse ( $filename, '\..*' );
$filename = $name ."_".$timestamp. $extension;
#upload the image
my $upload_filehandle =$query->param("img");
open ( UPLOADFILE, ">$upload_dir/$filename" ) or die "$!";
binmode UPLOADFILE;
while ( <$upload_filehandle> )
{
print UPLOADFILE;
}
close UPLOADFILE;
Then I do resize for the image. My problem is that the image is not uploaded. I have an empty file having the name of $filename. I omitted the part related to resize and I still have the code. So I'm sure that the file is not being uploaded correctly. Am I missing any library?
Any help?Plz..
You need to change
my $upload_filehandle =$query->param("img");
to
my $upload_filehandle =$query->upload("img");
according to this tutorial.
Hope it helps.
I figured out why: As pointed out in the CGI.pm docs, the form's encoding type must be multipart/form-data. When I added that, everything worked.
added this "ENCTYPE='multipart/form-data'" instead of encoding.
> <form action="/post.pl" method="post" ENCTYPE='multipart/form-data'>
and it worked