I am trying to apply image filters to an image and update a file element every time a filter is clicked. So that would be pseudo code. Its still being said that the file field is null, and I'm not sure why.
I am trying to transfer a file to my php script that handles uploads, but I'm not sure how to do this in the script, because my javascript skills are not good enough.
HTML
<div id="uploadPic" class="modal fade" > <form method="post" id="fileinfo" name="fileinfo" onsubmit="return submitForm();"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header" style="background:#f3f3f3;"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> <h4 class="modal-title" style="color:black;">Choose picture to upload as profile pic.</h4> </div> <div class="modal-body"> <div id="filterContainer" style='width:400px;'> <ul id="filters" style='width:400px;'> <li> <a href="#" id="normal">Normal</a> </li> <li> <a href="#" id="vintage">Vintage</a> </li> <li> <a href="#" id="lomo">Lomo</a> </li> <li> <a href="#" id="clarity">Clarity</a> </li> <li> <a href="#" id="sinCity">Sin City</a> </li> <li> <a href="#" id="sunrise">Sunrise</a> </li> <li> <a href="#" id="crossProcess">Cross Process</a> </li> <li> <a href="#" id="orangePeel">Orange Peel</a> </li> <li> <a href="#" id="love">Love</a> </li> <li> <a href="#" id="grungy">Grungy</a> </li> <li> <a href="#" id="jarques">Jarques</a> </li> <li> <a href="#" id="pinhole">Pinhole</a> </li> <li> <a href="#" id="oldBoot">Old Boot</a> </li> <li> <a href="#" id="glowingSun">Glowing Sun</a> </li> <li> <a href="#" id="hazyDays">Hazy Days</a> </li> <li> <a href="#" id="herMajesty">Her Majesty</a> </li> <li> <a href="#" id="nostalgia">Nostalgia</a> </li> <li> <a href="#" id="hemingway">Hemingway</a> </li> <li> <a href="#" id="concentrate">Concentrate</a> </li> </ul> </div> <div id='output_file'></div> <div id="output"></div> <div id="photo"> <a href="#" class="downloadImage" target="_blank" download="photo.png">Download Image</a>- </div> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> <input type="submit" value="Upload" class="btn btn-info" data-dismiss="modal" onClick="return submitForm();"/> </div> </div> </div> </form> </div>
JavaScript:
$(function() { var maxWidth = 500, maxHeight = 500, photo = $('#photo'), originalCanvas = null, filters = $('#filters li a'), filterContainer = $('#filterContainer');
PHP:
<?php $username = $_POST["username"]; $timestamp = $_POST["timestamp"]; $allowedExts = array("gif", "jpeg", "jpg", "png"); $temp = explode(".", $_FILES["file"]["name"]); $extension = end($temp); if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/jpg") || ($_FILES["file"]["type"] == "image/pjpeg") || ($_FILES["file"]["type"] == "image/x-png") || ($_FILES["file"]["type"] == "image/png")) && ($_FILES["file"]["size"] < 200000) && in_array($extension, $allowedExts)) { if ($_FILES["file"]["error"] > 0) {
In accordance with the comments of the district, I do the following:
This is adding base64 to the form data on my main page every time the filter is clicked. Thus, when someone clicks on a download, he sends this data to a pho script.
var fd = new FormData(document.getElementById("fileinfo")); fd.append("file_upload", clone[0].toDataURL("image/png;base64;"));
Here is my current JavaScript for handling an AJAX request:
function submitForm() { if (get_user != logged_username) {} else { var d = new Date(); var time = d.getTime();
and then php:
<?php
log output:
data: images / PNG; base64, iVBORw0KGgoAAAUsUhEUgAAAfQAAAH0CAYAAADL1t + KAAAgAElEQ ... P3PeerM0GN4J7vE4xyTdlT34hvfOMbuiYnL6xlqkUu4v8BZXAIWAIWAJAW5AIWAJAWA
php returns the inability to save the file, and it saves the file with 0 bytes.
This works, but it puts a file with 0 bytes, and I'm not sure why.