Monday, March 27, 2023

Create Gmail SMTP and create Client id, Client secret key in google console

Hello 

Today I saw you how to create google smtp api and client id, client key in console.

This process will help you and client also for get client id and client key without sharing password.

1: Open this url with your google id password : 

https://console.cloud.google.com/


Click on left top side, this popup is open. Click on "New Project" text.

2: Create project details with project name and select organization and location.


3: Now one home page like open. Click on "API and Services" from quick links. It will open this type of window.  Click on "Library"


4: Now many libraries are listed. Please select "Gmail API".


5: Click on "Enable" text. 


6: Now click on "OAuth consent screen" and click on "Create".


Fill details and click on only 3 fields :   No need to feel all fields.
1:App Name
2:User Support Email
3:Developer Contact EMail Address




And click on "Save And Continue" button at bottom.

Important step

7: Click on left side "Credentials" and click on "Create Credentials" like this.


Now click on "OAuth Client ID". Create name and you will get credentials.

Edit:
Note: Also create user for it and set your app to  "Publish". If you set as "Test" mode then after 7 days email smtp is not working. you have to re-authenticate it. For avoid this issue, please set your mode as publish.

Tuesday, March 21, 2023

How to Fix the “Sorry, This File Type Is Not Permitted for Security Reasons” Error in wordpress

 Hello 

Today I saw you how to upload svg file to wordpress website.

Have you ever encountered the “Sorry, this file type is not permitted for security reasons” error? Even though this is a common error message, it can sometimes be annoying. But you need not worry; while this message may appear inauspicious, it only signifies that WordPress does not support the file type you attempted to upload.


1. What Triggers ‘Sorry, This File Type Is Not Permitted for Security Reasons’?

For security concerns, WordPress restricts the file types you can upload through your site’s admin – photos, videos, documents, and audio. If you’re trying to upload a file not supported by WordPress, you are bound to get this error.

file upload error


If you only upload file types that WordPress supports, you probably won’t come across the error message. Next, let’s have a look at what those file types are.


2 File Types Allowed in WordPress

WordPress enforces limitations on the file types you can upload for security reasons. By default, the file types you can upload are as follows:

Images: .png, .gif, .jpg, .jpeg, .ico, .bmp, .tiff, .webp, .heic.

Documents: .pdf, .doc, .docx, .xls, .xlsx, .ppt, .pptx, .pps, .ppsx, .odt, .PSD

Audio: .wav, .mp3, .m4a, .m4b, .aac, , .ra, .ram, .ogg, .oga, .flac, .mid, .midi, .wma, .wax, .mka

Video: .mp4, .m4v, .mpg, .mov, .wm, .wmx, .wmv, .avi, .mkv, .webm, .mpeg, .mpe, .flv, .divx, .ogv, .3gp, .3gpp, .3g2, .3gp2

These are all the most common file types. Any file that is not one of the permitted file types cannot be uploaded to the media library. You’ll get the “Sorry, this file type is not permitted for security reasons” error in WordPress when you try to upload them.

Now let’s take a look at how to fix this error message.


3 How to Fix ‘Sorry, This File Type Is Not Permitted for Security Reasons’

3.1 Check and Correct the File Type Extension Spelling

Check the extension of the file you’re trying to upload before making any changes to your WordPress settings or files. It’s possible that when you saved the file, you altered the extension unintentionally.

When you get this error, the first thing you should do is double-check that the file extension is correct. While editing or saving a file on your computer, you may accidentally erase or mistype a file name extension. So you need to check and correct the file type extension spelling and then upload the file.

3.2 Edit the wp-config.php File to Upload Any File Type

To upload all types of file extensions on your site, you can edit your wp-config.php file and add a one-liner code.

We recommend you always make a backup of your wp-config.php file before modifying it. Even a minor file issue can turn your site inaccessible. Once you’ve made a copy of your wp-config.php file, follow the instructions below to allow any file type upload.

You can access your wp-config.php file via FTP and look for the file in your site’s root directory. Click on View/Edit to open the file

Scroll down to the bottom of the file, and you’ll notice the line /* That’s all, stop editing! Happy blogging. */. Before this line, paste the following one-liner code:


define('ALLOW_UNFILTERED_UPLOADS', true);


Once you’ve added the code, save the changes, re-upload the file, and now you’ll be able to upload the new file types on your site.

This is a simple approach; however, it isn’t ideal for every website. You may want to specify which file types are allowed if multiple users upload files to your WordPress site. In such a case, you can edit the functions.php file and upload only certain file types.

3.3 Edit the functions.php File to Upload Any File Type

If you are code-savvy, you can add the upload_mimes filter to the theme’s functions.php file. This method will allow certain file types so that you have control over what’s uploaded to your site and prevent file upload vulnerabilities. 

Once you’ve backed up your site, access your functions.php file via FTP. You can locate the file in your theme’s folder in the wp-content directory: Right-click and select View/Edit as shown below.

Add the following code snippet in the functions.php file from the theme files. The below code allows SVG and SVGZ files. You can modify the code depending on the type of file you want to upload.


/**
 * Function to change the allowed mime types
 *
 * @param  mixed $mimes Allowed mime types.
 * @return mixed $mimes Updated mime types list.
 */
function my_custom_mime_types( $mimes ) {
// New allowed mime types.
$mimes['svg']  = 'image/svg+xml';
$mimes['svgz'] = 'image/svg+xml';
return $mimes;
}
add_filter( 'upload_mimes', 'my_custom_mime_types' );


Once you’ve added the above code, don’t forget to save your changes. Beginners may have difficulty adding code to their functions.php or wp-config.php files. You can then utilize a WordPress plugin to allow new file types in WordPress.

3.4 Allow New File Types By Using a Plugin (This is my favourite. I used this way in many websites.)

Various plugins are available that allow uploading the file types to your site, such as the File Uploads Type plugin. At first, install and activate the File Uploads Type plugin from your WordPress dashboard.



There are two ways to permit uploads for a specific MIME type. The first is to select the box corresponding to the desired MIME type. However, if your desired type is not listed, you can add your custom file type at the bottom of the page. Click on the Save Settings button to save your changes.


You’ll now be able to add your file type without receiving an error message.


3.5 Change the Multisite Network Settings

You can easily add more file types if you’re running a multisite installation. To do so, navigate to Settings > Network Settings from your WordPress dashboard. Scroll down to Upload Settings, and you can add the extension for the file type in the input field next to Upload file types, as shown below.


Click on Save Changes once you’ve added your file types.


3.6 Secure the WordPress File Uploads

Allowing users to upload files in various formats may be easy, but it also leads to security concerns. You can make your site more secure while still allowing specific upload types. To do so, you should:

Limit the types of files uploaded to only those truly necessary.

Limit the file size that can be uploaded.

Use a WordPress security plugin to keep an eye on your site for flaws.

Scan your WordPress site for possibly malicious code regularly.

Non-registered users should be limited to only uploading the file types that they require. A file upload form is an ideal way to do this.

3.7 Contact Your Hosting Provider

If you’ve tried all of the methods above but still receive an error message, contact your WordPress hosting provider’s support team and explain your situation.

Your provider likely imposes stronger file-type restrictions than WordPress does by default. If the instructions above fail to resolve the ‘sorry, this file type is not permitted for security reasons’ error, contact your provider’s customer support.

Wednesday, March 15, 2023

Install Gatsby JS in ubuntu

Hello

Today I saw you How to install GatsbyJS in ubuntu. Follow these steps.


1. First go to your wordpress website folder, open terminal and run these commands.

2. sudo npm install -g gatsby

sudo npm install -g gatsby-cli

Check version : gatsby --version


3. To create a new site using the official WP Gatsby starter, run "gatsby new gatsby-site". That will fetch this starter and put it in a new directory called "gatsby-site" .

If you found any error here please delete this folder "gatsby-site" in wordpress directory. And again run above step.


4. now go to and "gatsby-site" by "cd gatsby-site" run this : "gatsby develop"


it will take 1 minute. Now you can find 2 url in terminal like these: 

http://localhost:8000/

http://localhost:8000/___graphql


5. This is your gatsby site: http://localhost:8000/  If you want to edit this, go to "src->pages" folder. You can find index.js. You can edit it. You can also edit "srs->templates" and "src->components". 



Monday, March 6, 2023

Display database tables and its data dynamically in php mysql

Dear Friends,

Today I face problem with MySQL Workbench. PhpMyAdmin is not running in my system. I saw that database is updated but not displayed effect in Mysql Workbench. So this code will help you to see table's data. All tables with data displayed in tab.


<!DOCTYPE html>
<html>
<head>
<title>Display Database Tables</title>
<style>
/* Style the tab */
.tab {
overflow: hidden;
border: 1px solid #ccc;
background-color: #f1f1f1;
}
/* Style the buttons inside the tab */
.tab button {
background-color: inherit;
float: left;
border: none;
outline: none;
cursor: pointer;
padding: 14px 16px;
transition: 0.3s;
font-size: 17px;
}
/* Change background color of buttons on hover */
.tab button:hover {
background-color: #ddd;
}
/* Create an active/current tablink class */
.tab button.active {
background-color: #ccc;
}
/* Style the tab content */
.tabcontent {
display: none;
padding: 6px 12px;
border: 1px solid #ccc;
border-top: none;
}
</style>
</head>
<body>
<div class="tab">

<?php
// MySQLi connection
$mysqli = new mysqli("localhost", "Database username", "Database password", "Database name");

// Check connection
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: " . $mysqli->connect_error;
exit();
}

// Get all table names in the database
$tables = array();
$result = $mysqli->query("SHOW TABLES");
while ($row = $result->fetch_array(MYSQLI_NUM)) {
$tables[] = $row[0];
}

// Loop through each table and display its name, column names, and data
foreach ($tables as $table) {
echo "<button class='tablinks' onclick='openTab(event, \"$table\")'>$table</button>";
}
?>

<!-- Create tab content for each table -->
<?php
foreach ($tables as $table) {
echo "<div id='$table' class='tabcontent'>";
echo "<h2>Table: $table</h2>";
echo "<table border='1'>";
$result = $mysqli->query("SELECT * FROM $table");
$fields = $result->fetch_fields();
echo "<tr>";
foreach ($fields as $field) {
echo "<th>$field->name</th>";
}
echo "</tr>";
while ($row = $result->fetch_assoc()) {
echo "<tr>";
foreach ($row as $value) {
echo "<td>$value</td>";
}
echo "</tr>";
}
echo "</table>";
echo "</div>";
}

// Close MySQLi connection
$mysqli->close();
?>
</div>

<script>
// Show default table
document.getElementById("<?php echo $tables[0]; ?>").style.display = "block";



// Function to open a specific tab content
function openTab(evt, tabName) {
  var i, tabcontent, tablinks;

  // Hide all tab content
  tabcontent = document.getElementsByClassName("tabcontent");
  for (i = 0; i < tabcontent.length; i++) {
    tabcontent[i].style.display = "none";
  }

  // Remove active class from all tab links
  tablinks = document.getElementsByClassName("tablink");
  for (i = 0; i < tablinks.length; i++) {
    tablinks[i].className = tablinks[i].className.replace(" active", "");
  }

  // Show the selected tab content and add active class to the selected tab link
  document.getElementById(tabName).style.display = "block";
  evt.currentTarget.className += " active";
}
</script>
</body>
</html>


Wednesday, March 1, 2023

wordpress error 404 when set Permalink structure as Post Name

Hello

I face many time 404 error when I set "Permalink structure" as "Post Name". Here I gave you my solution for this.

Go to your wordpress directory and make .htaccess file and put this code:


<IfModule mod_rewrite.c>

RewriteEngine On

RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

RewriteBase /real611/

RewriteRule ^index\.php$ - [L]

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule . /real611/index.php [L]

</IfModule>


Here "real611" is your wordpress folder name. You have to replace it with your wordpress folder name.



Create file "wp.conf" in /etc/apache2/sites-available/wp.conf

by commands, do these steps:-

1. Go to this folder and open terminal from this folder "sites-available" and type this command : sudo vi wp.conf

You will be notifiy for enter password.

2. After entered password, editor is open. Copy paste this code.



<Directory /var/www/html/>

Options Indexes FollowSymLinks

AllowOverride All

Require all granted

</Directory>



3. Now save this file by this commands.

To save a file in Vim / vi, press Esc key, type :w and hit Enter key

One can save a file and quit vim / Vi by pressing Esc key, type :x and hit Enter key





4. Now restart your web server details below:

  1. sudo a2ensite wp.conf
  2. systemctl reload apache2
  3. service apache2 reload
  4. sudo a2enmod rewrite
  5. systemctl restart apache2


Now you can set "Permalink structure" as "Post Name"