DeveloperBreeze

// File Upload PHP Script

$targetDir = 'uploads/';
$targetFile = $targetDir . basename($_FILES['file']['name']);

if (move_uploaded_file($_FILES['file']['tmp_name'], $targetFile)) {
    echo 'File uploaded successfully.';
} else {
    echo 'Error uploading file.';
}

Continue Reading

Discover more amazing content handpicked just for you

Code
javascript

Dynamic and Responsive DataTable with Server-Side Processing and Custom Styling

  • serverSide: true enables server-side pagination, sorting, and filtering.
  • processing: true displays a processing indicator while fetching data.
  • The ajax object defines how data is fetched from the server.
  • url: Endpoint for fetching data.
  • type: HTTP method (GET).
  • error: Logs errors that occur during the AJAX request.
  • dataSrc: Processes the server's response. It logs the data and returns records for display.

Oct 24, 2024
Read More
Tutorial
php

Handling HTTP Requests and Raw Responses in Laravel

Sometimes, you might receive raw responses in formats other than JSON, such as a query string or plain text. Here’s how to handle and process raw responses:

use Illuminate\Support\Facades\Http;

$response = Http::post('https://api.example.com/endpoint', [
    'key1' => 'value1',
    'key2' => 'value2',
]);

$rawResponse = $response->body(); // Get the raw response as a string
dd($rawResponse);

Oct 24, 2024
Read More
Article
javascript

20 Useful Node.js tips to improve your Node.js development skills:

No preview available for this content.

Oct 24, 2024
Read More
Tutorial
javascript

AJAX with JavaScript: A Practical Guide

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>POST Request with Fetch</title>
</head>
<body>
    <form id="postDataForm">
        <input type="text" id="title" placeholder="Enter title" required>
        <input type="text" id="body" placeholder="Enter body" required>
        <button type="submit">Submit</button>
    </form>
    <div id="postDataOutput"></div>

    <script>
        document.getElementById('postDataForm').addEventListener('submit', function(e) {
            e.preventDefault();

            const title = document.getElementById('title').value;
            const body = document.getElementById('body').value;

            fetch('https://jsonplaceholder.typicode.com/posts', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json'
                },
                body: JSON.stringify({
                    title: title,
                    body: body
                })
            })
            .then(response => response.json())
            .then(data => {
                document.getElementById('postDataOutput').innerHTML = `
                    <h3>Data Submitted:</h3>
                    <p>Title: ${data.title}</p>
                    <p>Body: ${data.body}</p>
                `;
            })
            .catch(error => console.error('Error:', error));
        });
    </script>
</body>
</html>
  • The form is submitted without a page reload by preventing the default form submission behavior.
  • We send a POST request to the API using fetch(), including the form data as JSON in the request body.
  • The server's response is displayed on the page.

Sep 18, 2024
Read More
Tutorial
javascript

Advanced JavaScript Tutorial for Experienced Developers

const sym1 = Symbol('description');
const sym2 = Symbol('description');

console.log(sym1 === sym2); // Output: false

In this example, sym1 and sym2 are both symbols with the same description, but they are different and unique values.

Sep 02, 2024
Read More
Tutorial
javascript

Getting Started with Axios in JavaScript

axios.get('https://jsonplaceholder.typicode.com/posts/1')
  .then(response => {
    console.log(response.data);
  })
  .catch(error => {
    console.error('Error fetching data:', error);
  });

In this example:

Sep 02, 2024
Read More
Cheatsheet
solidity

Solidity Cheatsheet

  • Fallback: Called when no other function matches or if no data is provided.

  • Receive: Specifically handles Ether transfers.

Aug 22, 2024
Read More
Tutorial
bash

Creating and Managing Bash Scripts for Automation

Cron is a time-based job scheduler in Unix-like systems that allows you to automate script execution.

   crontab -e

Aug 19, 2024
Read More
Code
javascript

React Custom Hook for API Requests

No preview available for this content.

Aug 12, 2024
Read More
Code
python

Python Logging Snippet

  • Auditing: Keep track of important operations, errors, and exceptions for auditing purposes.

Logging is a fundamental aspect of software development, helping developers understand and maintain complex systems effectively. This snippet provides a robust starting point for adding logging capabilities to your applications.

Aug 08, 2024
Read More
Code
javascript

Fetching Chuck Norris Jokes from API in JavaScript

No preview available for this content.

Jan 26, 2024
Read More
Code
php

File Upload with Type Validation in PHP

No preview available for this content.

Jan 26, 2024
Read More
Code
javascript

JavaScript File Upload using Fetch API and FormData

No preview available for this content.

Jan 26, 2024
Read More
Code
php

Upload and Store File in Laravel

No preview available for this content.

Jan 26, 2024
Read More
Code
bash

Various cURL Examples for API Interactions

# Update resource with PUT request
curl -X PUT https://api.example.com/resource/123 \
    -H 'Content-Type: application/json' \
    -d '{"key": "updated_value"}'

# Retrieve data with GET request
curl https://api.example.com/data

# Send data with POST request to a form endpoint
curl -X POST https://api.example.com/form-endpoint \
    -d 'param1=value1&param2=value2'

# Delete resource with DELETE request and Authorization header
curl -X DELETE https://api.example.com/resource/456 \
    -H 'Authorization: Bearer your_access_token'

# Upload a file with POST request to an upload endpoint
curl -X POST https://api.example.com/upload-endpoint \
    -H 'Content-Type: multipart/form-data' \
    -F 'file=@/path/to/your/file.txt'

# Send JSON data with POST request to a secured endpoint with headers and authorization
curl -X POST https://api.example.com/post-endpoint \
    -H 'Content-Type: application/json' \
    -H 'Authorization: Bearer your_access_token' \
    -d '{"username": "john_doe", "password": "secretpassword"}'

# Send JSON data with POST request to an endpoint with cookies
curl -X POST https://example.com/api/endpoint \
    -H 'Content-Type: application/json' \
    -H 'Cookie: sessionid=your_session_id' \
    -d '{"key1": "value1", "key2": "value2"}'

Jan 26, 2024
Read More
Code
javascript

Promise-based Execution of Python Code with jsPython

No preview available for this content.

Jan 26, 2024
Read More
Code
javascript python

Execute Python Code Using Skulpt

No preview available for this content.

Jan 26, 2024
Read More
Code
javascript

POST Request with Fetch API and JSON Data

No preview available for this content.

Jan 26, 2024
Read More
Code
python

Bybit Futures API Integration Using ccxt Library with Error Handling

No preview available for this content.

Jan 26, 2024
Read More

Discussion 0

Please sign in to join the discussion.

No comments yet. Start the discussion!