$ is not defined during a Magento installation through cPanel - javascript

I am trying to install Magento community edition 1.9.2.1 into cPanel through Godaddy. I have so far extracted the tar file into the file manager, moved all the items in the Magento folder into root, and given folders proper permissions to run.
When I go into my website to open up the installation wizard I see this
I cannot click the continue button it doesn't work. When I inspect the page I get these errors.
I think its a jQuery problem. Looks like the website doesn't load any JavaScript. I tried adding a jQuery CDN link to the head but no avail. I have saved a jQuery CDN into my file system and called it through head still nothing.
I don't know what's the problem. JavaScript is enabled in my browser, so it should work.

i think this should be permission issue.i have attached a code,copy that in a new file(eg. magento-cleanup.php ) and upload to your magento root and run it using url(http://youdomain/magento-cleanup.php). it helps you to fix permission issue.
<?php
## Function to set file permissions to 0644 and folder permissions to 0755
function AllDirChmod( $dir = "./", $dirModes = 0755, $fileModes = 0644 ){
$d = new RecursiveDirectoryIterator( $dir );
foreach( new RecursiveIteratorIterator( $d, 1 ) as $path ){
if( $path->isDir() ) chmod( $path, $dirModes );
else if( is_file( $path ) ) chmod( $path, $fileModes );
}
}
## Function to clean out the contents of specified directory
function cleandir($dir) {
if ($handle = opendir($dir)) {
while (false !== ($file = readdir($handle))) {
if ($file != '.' && $file != '..' && is_file($dir.'/'.$file)) {
if (unlink($dir.'/'.$file)) { }
else { echo $dir . '/' . $file . ' (file) NOT deleted!<br />'; }
}
else if ($file != '.' && $file != '..' && is_dir($dir.'/'.$file)) {
cleandir($dir.'/'.$file);
if (rmdir($dir.'/'.$file)) { }
else { echo $dir . '/' . $file . ' (directory) NOT deleted!<br />'; }
}
}
closedir($handle);
}
}
function isDirEmpty($dir){
return (($files = #scandir($dir)) && count($files) <= 2);
}
echo "----------------------- CLEANUP START -------------------------<br/>";
$start = (float) array_sum(explode(' ',microtime()));
echo "<br/>*************** SETTING PERMISSIONS ***************<br/>";
echo "Setting all folder permissions to 755<br/>";
echo "Setting all file permissions to 644<br/>";
AllDirChmod( "." );
echo "Setting pear permissions to 550<br/>";
chmod("pear", 550);
echo "<br/>****************** CLEARING CACHE ******************<br/>";
if (file_exists("var/cache")) {
echo "Clearing var/cache<br/>";
cleandir("var/cache");
}
if (file_exists("var/session")) {
echo "Clearing var/session<br/>";
cleandir("var/session");
}
if (file_exists("var/minifycache")) {
echo "Clearing var/minifycache<br/>";
cleandir("var/minifycache");
}
if (file_exists("downloader/pearlib/cache")) {
echo "Clearing downloader/pearlib/cache<br/>";
cleandir("downloader/pearlib/cache");
}
if (file_exists("downloader/pearlib/download")) {
echo "Clearing downloader/pearlib/download<br/>";
cleandir("downloader/pearlib/download");
}
if (file_exists("downloader/pearlib/pear.ini")) {
echo "Removing downloader/pearlib/pear.ini<br/>";
unlink ("downloader/pearlib/pear.ini");
}
echo "<br/>************** CHECKING FOR EXTENSIONS ***********<br/>";
If (!isDirEmpty("app/code/local/")) {
echo "-= WARNING =- Overrides or extensions exist in the app/code/local folder<br/>";
}
If (!isDirEmpty("app/code/community/")) {
echo "-= WARNING =- Overrides or extensions exist in the app/code/community folder<br/>";
}
$end = (float) array_sum(explode(' ',microtime()));
echo "<br/>------------------- CLEANUP COMPLETED in:". sprintf("%.4f", ($end-$start))." seconds ------------------<br/>";
?>

Related

PHP - Create a directory listing of specified folder

I've got small piece of code which I'm using to scan a certain directory on my server for all the files and folders inside. But there's a catch... It can only scan the specified folder, and no sub-directories. Let's say share/ is the root directory for this scan, if there are files in any sub-directory like share/folder/file.png they won't be listed, where the entire purpose of my project is to create an HTML file explorer.
This is the code I'm using to receive the list of files from the server to later display it in the browser using JavaScript:
<?php
$listFiles = array();
if ($handle = opendir('./share')) {
while (false !== ($entry = readdir($handle))) {
if ($entry != "." && $entry != "..") {
$listFiles[] = $entry;
}
}
closedir($handle);
}
$FS_files = json_encode($listFiles);
?>
And then I "push" it rude to my actual JavaScript code like this:
let FS_files = <?php echo $FS_files ?>
The code I above basically generates an array of file names from scanned directory. What I wanna know is how can I get an entire JSON tree of files in this directory and all folders inside it, or possibly change my code so it works that way?
<?php
function scanFolder($dir) {
$result = array();
$cdir = scandir($dir);
foreach ($cdir as $key => $value) {
if (!in_array($value,array(".",".."))) {
if (is_dir($dir . DIRECTORY_SEPARATOR . $value)) {
$result[$value] = scanFolder($dir . DIRECTORY_SEPARATOR . $value);
} else {
$result[] = $value;
}
}
}
return $result;
}
$FS_files = json_encode(scanFolder("./share"));
?>
The function scans the folder and checks each entry with is_dir. If its true, this folder is scanned with the same function.

I want to fetch all dir name

I need seniors help to make dropdown list of root directories using php. I created almost but having one issue is not getting root directory.
Like home/abc/ all dir I want
Code sample
<?
$dirs = array_filter(glob('/*'), 'is_dir'); //this code getting main root folders
print_r($dirs); // array showing root directory
?>
But I want to get all directories from home/username
is it possible?
Despite the clarification to the question I'm not 100% sure the following is what you are meaning. I took it to be that you wish to get all folders under the start location - in your case /home/username
The recursiveIterator classes are very useful for this sort of task.
/* The ROOT directory you wish to scan */
$dir = 'c:/wwwroot/images';
if( realpath( $dir ) ){
$dirs=array();
$dirItr=new RecursiveDirectoryIterator( realpath( $dir ), RecursiveDirectoryIterator::KEY_AS_PATHNAME );
foreach( new RecursiveIteratorIterator( $dirItr, RecursiveIteratorIterator::CHILD_FIRST ) as $file => $info ) {
if( $info->isDir() ) $dirs[]=realpath( $info->getPathName() );
}
echo '<pre>',print_r( $dirs, 1 ),'</pre>';
}
Loop through user's directory
The following code finds the user directory (compatible with Windows, Mac, and Linux) then recursively echo's the directory paths.
<?php
$dir = '';
if (strpos(php_uname(),"Linux") === 0) {
//linux
$dir = "/home/";
} else {
//windows and mac
$dir = "/users/";
}
$dir.=get_current_user();
$iterator = new DirectoryIterator($dir);
foreach ($iterator as $fileinfo) {
if ($fileinfo->isDir() && !$fileinfo->isDot()) {
echo $fileinfo->getPathName() . "\n";
// recursion goes here.
}
}
?>
Looping through the entire System
The AJAX method
Ajax is basically just a way of communicating to a server without having to refresh. What the following code does it lazy loads directories. So, as it's needed, it will load the next iteration for directories. I believe this would be what you want because printing everything from the root is a bit suicidal.
<?php
function filterDirectories($dir) {
$myDirs = scandir($_POST['dir']);
foreach ($myDirs as $key => $myDir) {
$path = str_replace('//','/',$dir . '/' . $myDir);
if (!is_dir($path) || $myDir === "." || $myDir === "..") {
unset($myDirs[$key]);
} else {
$myDirs[$key] = $path;
}
}
return array_values($myDirs);
}
if (isset($_POST['dir'])) {
echo json_encode(filterDirectories($_POST['dir']));
die();
}
?>
<body>
<form>
<div id="selectContainer">
</div>
</form>
</body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(function () {
"use strict";
var rootDir = "/";
function getDirectory(dir) {
$.post("#", {
dir : dir
}, function (data) {
var $select = $("<select>");
for (var i = 0, len = data.length; i < len; i++) {
$("<option>")
.text(data[i])
.attr('value',data[i])
.appendTo($select);
}
$("#selectContainer").append($select);
}, "json");
}
getDirectory(rootDir);
$("#selectContainer").on("change", "select", function () {
$(this).nextAll().remove();
getDirectory($(this).val());
});
});
</script>

How to recursively link javascript files to HTML

I have the following file structure:
root - dir1 - js_dir - file.js
- dir2 - inner_dir - header.php
The directory js_dir contains my javascript files. I'm trying to recursively add them to my header in header.php as follows:
header.php
<head>
<?php
$dir = '../../dir1';
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir), RecursiveIteratorIterator::SELF_FIRST );
foreach ( $iterator as $path ) {
if ($path->isDir()) {
print('<div> DIR : ' . $path . PHP_EOL . "</div>");
} else {
$path_parts = pathinfo($path);
$file_parts = $path_parts['extension'];
if ($file_parts == "js")
{
$array = explode("/opt/lampp/htdocs", $path);
unset($array[0]);
echo $path = implode("/", $array);
print("<div>http://localhost$path" . PHP_EOL . "</div>");
echo("<script src='http://localhost/$path'></script>");
}
}
}
?>
</head>
I, however, keep getting the error:
Fatal error: Uncaught UnexpectedValueException: RecursiveDirectoryIterator::__construct(../js): failed to open dir: No such file or directory in /opt/lampp/htdocs/root
How can I go about getting it to work?
Thank you all in advance.

can not download file in linux using php

<?php
// Make sure an ID was passed
include('include/function.php');
if(isset($_GET['id'])) {
// Get the ID
$id = intval($_GET['id']);
// Make sure the ID is in fact a valid ID
if($id <= 0) {
die('The ID is invalid!');
}
else {
// Connect to the database
$dbLink = new mysqli('localhost', 'root', 'jio', 'jio');
if(mysqli_connect_errno()) {
die("MySQL connection failed: ". mysqli_connect_error());
}
// Fetch the file information
$query = "
SELECT `id`,`date`,`expected_date`,`comname`,`type`,`name`,`path`,`mime`, `size`, `data`,`other_detail`,`remark`,`username`
FROM `depository`
WHERE `id` = {$id}";
$result = $dbLink->query($query);
if($result) {
// Make sure the result is valid
if($result->num_rows == 1) {
// Get the row
$row = mysqli_fetch_assoc($result);
// Print headers
header("Content-Type: ". $row['mime']);
header("Content-Length: ". $row['size']);
header("Content-Disposition: attachment; filename=". $row['name']);
}
else {
echo 'Error! No image exists with that ID.';
}
// Free the mysqli resources
mysqli_free_result($result);
}
else {
echo "Error! Query failed: <pre>{$dbLink->error}</pre>";
}
mysqli_close($dbLink);
}
}
else {
echo 'Error! No ID was passed.';
}
?>
I am trying to download file from path location(doc root) but getting a empty file download or corrupt file download. anyone can suggest me where i am wrong in above code or use anything else.
After sending the headers you need to read the file contents and send that data - the following isn't tested but is more or less what you need to do. You will probably need to adjust the $filepath variable according to the contents of $row['path'] from the sql result.
if($result->num_rows == 1) {
$row = mysqli_fetch_assoc($result);
header("Content-Type: ". $row['mime']);
header("Content-Length: ". $row['size']);
header("Content-Disposition: attachment; filename=". $row['name']);
/* you need to actually read the file and send it */
$filepath=$row['path'] . '/' . $row['name'];
if( !realpath( $filepath ) ) exit('Filepath '.$filepath.' is incorrect');
if( $file = fopen( $filepath, 'rb' ) ) {
while( !feof( $file ) and ( connection_status()==0 ) ) {
print( fread( $file, 1024*8 ) );
flush();
}
fclose( $file );
}
}

Special Characters encoding in textareas

I'm pulling contents from text files into a textarea to be used and noticed it appeared that slashes were appearing near quotes and apostrophes. I was able to resolve that by disabling magic quotes on the server, however I noticed that special characters still don't seem to display properly.
What I am trying to figure out is there a way when retrieving the file to decode/encode them properly or to encode them so they're UTF 8 compliant in the first place? Below is my coding for retrieving the files:
<?php
$directory = $directory = 'users/' . $_SESSION['username'];
$filesContents = Array();
$files = scandir( $directory ) ;
foreach( $files as $file ) {
if ( ! is_dir( $file ) ) {
$filesContents[$file] = file_get_contents($directory , $file);
echo '<option value="'. $file .'">' . $file . '</option>';
}
}
?>
</select>
and below is my save script:
if($_POST['Action'] == "SAVE") {
// If a session already exists, this doesn't have any effect.
session_start();
// Sets the current directory to the directory this script is running in
chdir(dirname(__FILE__));
// Breakpoint
if( empty($_SESSION['username']) || $_SESSION['username'] == '' ) {
echo 'There is no session username';
}
if( empty($_POST['CodeDescription']) || $_POST['CodeDescription'] == '' ) {
echo 'There is no POST desired filename';
}
// This is assuming we are working from the current directory that is running this PHP file.
$USER_DIRECTORY = 'users/'.$_SESSION['username'];
// Makes the directory if it doesn't exist
if(!is_dir($USER_DIRECTORY)):
mkdir($USER_DIRECTORY);
endif;
// Put together the full path of the file we want to create
$FILENAME = $USER_DIRECTORY.'/'.$_POST['CodeDescription'].'.txt';
if( !is_file( $FILENAME ) ):
// Open the text file, write the contents, and close it.
file_put_contents($FILENAME, $_POST['Code']);
endif;
header('Location: mysite.site/evo/codesaveindex.php?saved=1&file='.$FILENAME);
}
?>

Categories