class.upload.php is a powerful and mature PHP class to manage uploaded files, and manipulate images in many ways. The script is available under a GPL license.
more info about the class
<form id="fileUp" enctype="multipart/form-data" method="post" action="#"> <input type="file" size="32" id="fileInput" name="image_field" value=""> <input type="button" > </form>
function upload(){ var filename = $('input[type=file]').val().split('\\').pop(); //alert(filename); var path = $('input[type=file]').val(); $.ajax({ headers: { "Cache-Control": "no-cache","X-Requested-With":"XMLHttpRequest","X-File-Name": filename }, url:'testAjax.php', data:{imageName:'image_field',path:path}, type:'POST', success: function(data){ $('#error').html(data); }, }); }
require_once('../include/upload.php'); if (isset($_SERVER['HTTP_X_FILE_NAME']) && isset($_SERVER['CONTENT_LENGTH'])) { $handle = new Upload('php:'.$_SERVER['HTTP_X_FILE_NAME']); if ($handle->uploaded) { echo "uploaded"; } else{ echo 'error : ' . $handle->error; } }
my html code
my js code
my php code
output > error : Can't read image source. Not an image?.