Showing posts with label play php. Show all posts
Showing posts with label play php. Show all posts

Wednesday, February 8, 2023

move files from one folder to another by php code if you have no access to cpanel

 Hello.

TOday I will explain how to move files one folder to another folder in server with php code. Recently I face problem to move files from my computer to server. SO i make zip file ad upload it to server and i unzip it. But it creates a folder and put all files into that folder. My cpanel has not enough rights to move all files. IT has right only for one by one file move. It is very tedious job. SO I make this php code for move files.


<?php

//File Manager - Home Folder: dede.cptost-h.net/public_html/wp-includes/files_zip_0/

//File Manager - Home Folder: dede.cptost.h.net/public_html/wp-admin/wpadmin_zip_0/

$dir = "wp-admin/wpadmin_zip_0";

$new_location = "wp-admin/";

$i = 1;

if ($handle = opendir($dir)) {

    while (false !== ($entry = readdir($handle))) {


        if ($entry != "." && $entry != "..") {

            $file = $dir . "/" . $entry;

            $new_file = $new_location . $entry;


            if (!rename($file, $new_file)) {

                echo "<br>$i Error: Unable to move the file: $entry.";

            } else {

                echo "<br>$i File $entry moved successfully.";

            }

        }

        $i++;

    }


    closedir($handle);

} else {

    echo "Error: Unable to open the directory. <br>";

}


?>

Monday, January 30, 2017

How to recover phpmyadmin password

Assuming Xampp

You want to edit this file:

"\xampp\phpMyAdmin\config.inc.php"

change this line:$cfg['Servers'][$i]['password'] = 'WhateverPassword';

to whatever your password is. If you don't remember your password, then run this command in the Shell:

mysqladmin.exe -u root password WhateverPassword

where 'WhateverPassword' is your new password.

OR

There is a batch file called resetroot.bat located in the xammp folders 'C:\xampp\mysql'(works even if U are on mysql) run this and it will delete the phpadmin passwords. Then all you need to do is start the MySQL service in xampp and click the admin button.

Typical PHP codes

Typical PHP codes

 example for URL: http://example.com/folder1/folder2/yourfile.php?var=blabla#12345

$_SERVER["DOCUMENT_ROOT"] === /home/user/public_html
$_SERVER["SERVER_ADDR"]   === 143.34.112.23
$_SERVER['HTTP_HOST']     === example.com (or with WWW)
$_SERVER["REQUEST_URI"]   === /folder1/folder2/yourfile.php?var=blabla
__FILE__                  === /home/user/public_html/folder1/folder2/yourfile.php
basename(__FILE__)        === yourfile.php
__DIR__                   === /home/user/public_html/folder1/folder2 [same: dirname(__FILE__)]
$_SERVER["QUERY_STRING"]  === var=blabla

$_SERVER["REQUEST_URI"]   === /folder1/folder2/yourfile.php?var=blabla
parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH)  === /folder1/folder2/yourfile.php 
$_SERVER["PHP_SELF"]      === /folder1/folder2/yourfile.php

//if "YOURFILE.php" is included in "PARENTFILE.php" , and "PARENTFILE.PHP?abc"   is opened:
$_SERVER["PHP_SELF"]       === /parentfile.php
$_SERVER["REQUEST_URI"]    === /parentfile.php?abc
$_SERVER["SCRIPT_FILENAME"]=== /home/user/public_html/parentfile.php
str_replace($_SERVER["DOCUMENT_ROOT"],'', str_replace('\\','/',__FILE__ ) )  === /folder1/folder2/yourfile.php