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.
Just needed some advice on passing the filename to the class using AJAX query. I got it working but cannot get the correct filenaem being used.
I have created HTML code for the image file. <input type="file" id="file" name="file" /> <input type="button" class="button" value="Upload" id="but_upload">
Whent the upload button is pressed, the jQuery calls AJAX to pass the form data to the php-page for processing.
var fd = new FormData();
var files = $('#file')[0].files[0];
fd.append('file',files);
$.ajax({
url: 'ajax_upload_image.php',
type: 'post',
data: fd,
contentType: false,
processData: false,
success: function(response){
$("#ajax_result").html(response);
},
});
The AJAX passes the file information to the PHP.
However the class.upload.php does not seem to be able to have the reference to the tmp file created when pressing the HTML upload button.
I can get the upload to work using the below lines:-
The $_FILES['file']['name'] has the correct image filename. But if I pass this via $handle = new Upload($filename);, the class complains that the image file is not found.
If I then use the $filename = $_FILES['file']['tmp_name'];, the class find the image file and uploads it correctly, but the filename become the tmp-file name e.g. php3851.jpg instead of the original filename.
Is there a workaround for this? I did not seem to find any AJAX related queries.Reply
I have created HTML code for the image file.
<input type="file" id="file" name="file" />
<input type="button" class="button" value="Upload" id="but_upload">
Whent the upload button is pressed, the jQuery calls AJAX to pass the form data to the php-page for processing.
The AJAX passes the file information to the PHP.
However the class.upload.php does not seem to be able to have the reference to the tmp file created when pressing the HTML upload button.
I can get the upload to work using the below lines:-
The $_FILES['file']['name'] has the correct image filename. But if I pass this via $handle = new Upload($filename);, the class complains that the image file is not found.
If I then use the $filename = $_FILES['file']['tmp_name'];, the class find the image file and uploads it correctly, but the filename become the tmp-file name e.g. php3851.jpg instead of the original filename.
Is there a workaround for this? I did not seem to find any AJAX related queries.