I have an image (a captcha specifically) that I want to upload to my server using PHP (or if possible and better, only JQUERY)
I created an object with this code:
var newIMG = $("img[name='captchaImage']").clone();
But I cannot send it via jQuery's ajax method or else. (Even tried to manually add but no idea how to send an object as file)
What should be the simplest PHP / jQuery code to send this object?
Thanks in advance,
You can use jsupload plugin for this purpose.
One cannot upload files using AJAX..
You can also use an iframe to simulate uploading the files..
only jquery file upload is not possible you need php
and you can use the jQuery File Upload to upload file via ajax and jquery
Related
I am wanting to use the jQuery-File-Upload plugin located here https://github.com/blueimp/jQuery-File-Upload . I have implemented it for the most part but I am having trouble actually submitting the form. What I would like to do is when the user clicks on "Upload", instead of uploading it to a default directory on my server, I would like the page to POST so I can verify the files and then store them on my server. Is this possible to do with this plugin?
According to https://github.com/blueimp/jQuery-File-Upload/wiki/API it looks like you should be able to set an upload handler end point using a url parameter during initialization. I would image you could point that to a php/aspx/anything else location and handle it in there.
The File Upload widget is initialized by calling the fileupload method
on a jQuery collection with the target HTML element:
$('#fileupload').fileupload();
The target element is usually a container element holding the file
upload form, or the file upload form itself, but it can also be just
the file input element itself, if an url is provided as options
parameter.
The initialization method's first argument is an object that allows
you to initialize the widget with various Options:
$('#fileupload').fileupload({
url: '/path/to/upload/handler.json',
sequentialUploads: true
});
I added an image to PDF using $p->load_image (http://www.php.net/manual/en/function.pdf-fit-image.php). Now, I want to write JavaScript in it so that the user can manipulate image in the PDF. How can I get access to the image in PDF using Javascript?
Using PdfLib, add the following option to the load_image call:
"iconname=HelloImage" where HelloImage is the name of the image. The complete call would be,
$p->load_image('jpeg', 'C:/hello.jpg', "iconname=HelloImage");
In Javascript code, you can access it. For example,
var hello_image = this.getIcon("HelloImage");
Now hello_image points to the HelloImage.
i need to upload a file doc or pdf or rich text through jquery and smarty
i try to pass the file in jquery is given below
window.location.href= sitePath+'download?p='+$('#file').val();
but the p doesn't have value. how to get the file path or name and how can stored in server
in controller i write just pass the query to model is given below
$model=new download();
$id=$model->upload($param);
and i can't develop the model code....
please help me
You can't send files like that.
You should either submit a form with enctype="multipart/form-data" or use some AJAX uploader (which uses form submit to iframe and then stores a file using PHP script).
EDIT: Some references
http://www.w3schools.com/php/php_file_upload.asp - tutorial on how to upload a file using PHP
http://valums.com/ajax-upload/ - example of ajax uploader.
EDIT2: The problem is not with your model code but with the way you try to submit a file.
Upload a file, but not inside a form
For example :
<input type="file" name="taskuploadfile" />
<input type="button" name="taskupload" value="Task Upload" onclick="taskupload()" />
Using Ajax for javascript to php.
Can I get temp path of file in php or Is it possible ?
Use a library that can do it the best way that you can not reach even after a month of coding.
One of the best examples is JqUploader.
Here is the example: http://pixeline.be/experiments/jqUploader/test.php
You can use the File API to read the data and then send it via XHR as per an example on MDN or by using XHR2 as per HTML 5 Rocks' example.
These methods do have limited browser support though, so you are probably still better off using a real form and submitting to an iframe for the time being.
Since it looks like you are using dojo (from the tags you put in your post)... why not using the HTML5 multi-file upload widget ? It has a plugin to do ajax uploads...
More on that here : http://dojotoolkit.org/documentation/tutorials/1.6/uploader/
Reference documentation here : http://dojotoolkit.org/reference-guide/dojox/form/Uploader.html
It is not possible to do a file upload with ajax. The only trick is to use an IFRAME. And since you want to POST something to the server, you have to use a form tag.
<form action="upload_file.php" method="post" enctype="multipart/form-data">
Above is the line for a form to upload a file using php.
If i use the form as I wrote above I can get the various properties of the file to be uploaded from upload_file.php page.
Using jquery $.post , how can I do the same thing in upload_file.php ?
I googled but can't find the exact snippet of code necessary here.
Uploading images using jquery's ajax methods is a pain, generally involving dynamically creating an iframe and submitting a form inside it. I usually use this plugin: http://plugins.jquery.com/project/jquery-upload
You can write some php to echo the uploaded image data as a json object, which you can access once the upload is complete through the plugin.