I have a MyAccount page for my website which is going to have a form to allow the users to upload an image.
<from action='javascript:uploadFile'>
<input type='file' name='Upload'>
</form>
What I would like to do is have it call another .php file like:
<script type="text/javascript">
function uploadFile()
{
addPhoto.php giving files $id and Upload (from the form)
}
How can I achieve this without the user actually leaving the MyAccount page?
You can use include or require within a PHP file.
The include statement includes and evaluates the specified file.
You would need AJAX/jQuery to call it through JavaScript.
Documentation
Related
In php, i want call multiple php files in single button click action
just like that
<form action="php1.php , php2.php">
<form>
Is it possible ?? How can i call multiple files
In action attribute can be only one file, but you can use for example include.
<form action="php1.php">...</form>
And php1.php file:
<?php
include 'php2.php';
// process form data
Write whatever would be in php2.php as a function in php1.php and call it when you need.
I have a form as:<form action="test.php" method="post" name="testForm">
And I have validations of image upload in another file "upload.php" which has some code as:
if (in_array($_FILES['myfile']['type'], $types)) {
if(filesize($_FILES['myfile']['tmp_name']) < $max_size) {
$destination_path = getcwd().DIRECTORY_SEPARATOR."images".DIRECTORY_SEPARATOR;
So is there any way by which I can call the upload.php file without altering test.php file from form action attribute and perform my image upload validations.
you could use
include('upload.php');
OR
by using copy of the function into test.php
For the record, it would actually be better to use a jquery function which would submit the form to upload.php and then to test.php.
If you can alter the HTML code of your form, you could post to upload.php instead of test.php and then repost from upload.php to test.php (using CURL, for example)
If I get you right there are many ways. I recommend reading a bit in the manual:
include
functions.
class
filter
I have the form tag written as such:
<form id="form" action="mail.php" method="post"><!--form here--></form>
Currently this poses some problems, so I am switching the form action to an AJAX solution, however, I would like the AJAX function to be in an external JavaScript file. I know that you can link the form action attribute to a file, but how would I tell the form to look at the specific function in the file?
Any help is greatly appreciated!
just include the script file using <script src="file.js" type="text/javascript" /> and call the function in file wherever you want... you don not need to tell the program where to look for function .. all the script code is included within the file with the use of <script>
you can use:
onsubmit="SubmitFormViaAjax();return false;"
This way the form won't submit itslef (return false) and you can use any function in the included form to submit the form's data directly to the recipient via ajax.
Just make sure to include the ajax functions file in the page.
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.
I have a image upload form which adds an image to my server, although I'm wanting to load the information through jQuery ajax so the form doesn't refresh on submit.
At the moment I have
$('.img-form').submit(function(e) {
e.preventDefault();
$.post(document.href, $(".img-form").serialize());
});
Which seems to post the document, although i need to get it to call my ImageUpload() function from the PHP once I've pressed the submit.
My php function is called something like this,
<?php $Users->TutorialImageUpload(); ?>
If I understood correctly, you wish to upload an image without refreshing the page, and call your imageUpload() function.
As mentioned in the comments, you cannot upload in such a manner, however, what you could do
is put your upload form and code in a seperate php file and include it in the page as an iframe. This would upload your files withough refreshing the page.