Auto Uploading file

On the page where the button is,:

  1. Create the button which snaps the photo(I don’t kbnow how that is done)

<button>Snap photo!</button>

  1. Create a form (invisible form) with the value of anything….anything can be the value just make sure it isn’t empty
  2. Use javascript so that when the button is clicked,the form is submitted to a php page
  3. Mke the target of the form be an iframe that you have created so that when they snap the photo,it leads to the same page,without reloading the page]
    Here’s the code for what I just said:

    Snap

    </form>

<script>

function rad(){
document.getElementById(“crap”).submit();

</div>
  1. Make the file handler with this code:

    $errors = []; // Store all foreseen and unforseen errors here

    $fileExtensions = ['jpeg','jpg','png']; // Get all the file extensions

    $fileName = $_FILES['myfile']['name'];
    $fileSize = $_FILES['myfile']['size'];
    $fileTmpName = $_FILES['myfile']['tmp_name'];
    $fileType = $_FILES['myfile']['type'];
    $fileExtension = strtolower(end(explode('.',$fileName)));

    $uploadPath = $currentDir . $uploadDirectory . basename($fileName);

    if (isset($_POST['submit'])) {

    if (! in_array($fileExtension,$fileExtensions)) {
    $errors[] = "This file extension is not allowed. Please upload a JPEG or PNG file";
    }

    if ($fileSize > 1000000000) {
    $errors[] = "This file is more than 1GB. Sorry, it has to be less than or equal to 1GB";
    }

    if (empty($errors)) {
    $didUpload = move_uploaded_file($fileTmpName, $uploadPath);

    if ($didUpload) {
    echo basename($fileName) ;
    } else {
    echo "An error occurred somewhere. Try again or contact the admin";
    }
    } else {
    foreach ($errors as $error) {
    echo $error . "These are the errors" . "\n";
    }
    }
    }

    ?>

The only thing is that this uploads the image to your server not a ‘cloud folder’ …but it is a folder just place the cloud folder in your webserver then specify the name of the cloud folder in the$uploadDirectory = "/uploads/"; ie change ‘uploads’ to the name of your cloud folder….

Hopes this helps

Leave a Comment