Udemy
    •  
    •  
    •  
    •  
    •  
    •  
    •  
    •  
Turn what you know into an opportunity and reach millions around the world.
Learn More
Your cart is empty.
Keep shopping
Uploading images to PHP Server via AJAX
Rating: 4.5 out of 5(56 ratings)
3,058 students

Uploading images to PHP Server via AJAX

Explore how you can use AJAX and HTML forms to upload images to PHP servers
Created byLaurence Svekis
Last updated 11/2019
English

What you'll learn

  • How to send images to the server
  • Showing previews of images
  • Returning back the path of the new upload

Course content

2 sections21 lectures1h 27m total length
  • PHP upload course introduction5:03

    Learn to upload images to a PHP server using AJAX and form submissions, including decoding base64 images. Practice retrieving form file information, moving temp files, and building a web app.

  • System Setup and Resources4:27

    Learn to upload images to a PHP server using AJAX, set up a local development stack with Apache, PHP, and MySQL, and use Google CDN for AJAX calls.

  • HTML form setup and phpinfo check5:53

    Verify PHP is running with phpinfo and enable uploads in php.ini. Create an HTML form with a file input and post multipart form data to a PHP script using AJAX.

  • Get FILE information from submission3:07

    Learn how to capture file information from a submission in php using the $_FILES array and the input name to access uploaded content.

  • Image validation check in PHP8:12

    Validate uploaded images in PHP by checking type, size, and errors, and enforce allowed formats like jpeg and png. Use pathinfo and in_array to confirm extensions before uploading via AJAX.

  • Check upload size and check for errors5:57

    Validate image uploads by checking file size and errors before sending to a PHP server via AJAX, using thresholds like 100 kilobytes or 200 kilobytes, and preventing overwrites.

  • Save file to server PHP6:14

    learn to save uploaded images to a php server by creating an images directory, validating file existence and size, and moving the file to a target path with move_uploaded_file.

  • Source File upload to server0:29
  • Send to separate php file show image3:58

    Move image uploads to a separate php file (uploader.php) and update the index page to upload via ajax, then display the uploaded image with proper validation and feedback.

  • add jQuery and setup form for upload4:03

    Learn how to upload images to a PHP server using AJAX with jQuery, including setting up a form with an id, handling on submit, and preventing the default page reload.

  • Create AJAX request to PHP4:59

    Learn to create a form data object, capture the image, and send it with an AJAX post to uploader.php on the PHP backend, handling server responses without page refresh.

  • Preview image as base64 format8:56

    Learn to preview an uploaded image by listening for file input changes, reading the file as base64 with a file reader, and displaying the preview before AJAX upload to PHP.

  • Decode base64 image using PHP9:23

    Decode base64 images with PHP and AJAX to preview and save server-side copies, posting the base64 payload, decoding, and generating image paths for display.

  • Source Code index.html0:22
  • index.html code review5:29

    Review how index.html uses AJAX and jQuery to upload images to a PHP server, handling file input, file reader base64 encoding, and two AJAX calls for preview and save.

  • Source Code uploader.php0:25
  • uploader.php source code review6:27

    Review uploader.php source code, showing how it retrieves the uploaded file from input, validates image type and extension, and moves the file to the target path via ajax.

  • source code save.php0:02
  • code review save.php2:53

    Review code for saving base64 image data on a PHP server via AJAX, decoding to a blob, writing contents to a random image path, and returning the image path.

Requirements

  • jQuery AJAX
  • Basic PHP knowledge

Description

Explore how to upload images to your server using AJAX and PHP.

Please note this course covers PHP within the scope of saving files, specifically image files on your server.  Knowledge of PHP is a prerequisite  to this course.  AJAX is done via jQuery which is also a prerequisite to this course.  jQuery is only covered within simple AJAX calls and some element html updates.

This course covers a number of methods to store image data onto your server.

Learn how to create a Simple Form with a file input and submit the data to a PHP file.    Use PHP to check for valid images, file sizes and check for errors.

Using AJAX to submit form file contents to the server removes the need for a page reload and lets you make use of the response data and output it into your HTML.   Simple easy clean way to send images to your server.

BASE64 image data to PHP server can be used to create an image and save it to a file location on the server.  This method will ensure you have an image format as its not simply coping the file but actually using the encoded data to create the image file.   This method is useful when the image is also generated on the fly.

  • Source code is included to get you started quickly.
  • Resources and helpful links are also included

Taught by an instructor with over 18 years of real world web development experience, ready to answer any questions you may have.

Join now and start creating your own PHP applications today.

Who this course is for:

  • Web developers
  • PHP developers
  • Anyone who wants to learn how to upload images