0
I would like to know how to use PHP(include) commands within javascript, as in the example below:
jQuery(function($)
{
var $formteste = $('#fazer_upload_form')
var $formcadastro = $('#form_cadastro');
var $formlogin = $('#form_login');
$formteste.submit(function()
{
<?
include 'testar.php';
?>
$("#painel_fazer_upload").dialog('close');
return false;
});
});
When I use this way the modal doesn’t even open.
Testing.php would have that:
include("connection.php");
$arquivo_up = $_FILES['arquivo']['name'];
$arquivo_descricao = $_POST['arquivo_descricao'];
if(file_exists("Uploads/$arquivo_up"))
{
$a = 1;
while(file_exists("Uploads/[$a]$arquivo_up"))
{
$a++;
}
$arquivo_up = "[".$a."]$arquivo_up";
}
$extensao = pathinfo($arquivo_up, PATHINFO_EXTENSION);
if($extensao == "torrent")
{
if(move_uploaded_file($_FILES['arquivo']['tmp_name'], "Uploads/".$arquivo_up))
{
$arquivo_up = pathinfo($arquivo_up, PATHINFO_FILENAME);
$sqlupload = mysqli_query($coneccao, "INSERT INTO arquivos_downloads(nome, descricao) VALUES ('$arquivo_up', '$arquivo_descricao')");
header("location: index.php");
}
else
{
echo " <meta http-equiv='refresh' content='0; url=index.php'>
<script type='text/javascript'>alert('Erro no upload do arquivo!')</script>";
}
}
else
{
echo " <meta http-equiv='refresh' content='0; url=index.php'>
<script type='text/javascript'>alert('Formato Invalido!')</script>";
}
Note: I would like to know briefly how to do just that and not have to study something about it, thank you.
What is the goal, could you explain? that there needs ajax.
– rray
What’s inside of yours
teste.php
? You’ve seen how yourHTML
after the page renders? What exactly do you want to do by placingphp
within thejavascript
?– Erlon Charles
In a login system I would send to the test.php page, check the database, etc and then go back to index.php, instead of doing all this I would just like to call the test page,php, run everything right there and close the modal.
– Lucas Caresia
@Lucascarezia in this case you need to use AJAX. You know what that is?
– Sergio
I know what it is, but I only know his basics;C
– Lucas Caresia
@Lucascarezia reading suggestion: http://answall.com/q/43736/129, http://answall.com/q/6626/129
– Sergio
Thanks, I’ll give a study, but there is some "part" specific AJAX that I must study to do what I want ??
– Lucas Caresia
Really what you seek is ajax
– Erlon Charles
But there’s some specific part of him I must study to perform what I want ??
– Lucas Caresia
Put in the question the contents of this php file to understand what you want to do.
– Sergio
Yes, what should I do ??
– Lucas Caresia
Lucas, you came to see the question link at the top of the page the solution of your question?
– Math
Yeah, I ran some tests and I couldn’t do it the same way, so I voted to reopen.
– Lucas Caresia