<?php
$status = "";
if ($_POST["action"] == "upload")
{
// obtenemos los datos del archivo
$tamano = $_FILES["archivo"]['size'];
$tipo = $_FILES["archivo"]['type'];
$archivo = $_FILES["archivo"]['name'];
$prefijo = substr(md5(uniqid(rand())),0,6);
if ($archivo != "")
{
if ($tipo == "image/gif" || $tipo == "image/jpeg" || $tipo == "image/jpg")
{
$destino = "uploads/".$prefijo."_".$archivo;
if (copy($_FILES['archivo']['tmp_name'],$destino))
{
$status = "Archivo subido: <b>".$archivo."</b>";
}
else
{
$status = "Error al subir el archivo";
}
}
else
{
$status = "Error: solo se permite GIF o JPG";
}
}
else
{
$status = "Error al subir archivo";
}
}
?>
if(!is_uploaded_file($_FILES['archivo']['tmp_name']))
{
echo 'Error al subir la imagen';
return false;
}
if(!preg_match("#^(gif|jpg|jpeg|jpe|bmp|png)$#i", strtolower(mb_substr(strrchr($_FILES["archivo"]['name'];, "."), 1))))
{
echo 'error en la extension';
return false;
}
$mover = @move_uploaded_file($_FILES['archivo']['tmp_name'], $destino."/".$prefijo."_".$archivo);
if(!$mover)
{
echo 'no se a podidoca cargar la imagen';
return false;
}
if($_FILES["archivo"]['error'])
{
@unlink($destino);
echo 'error';
return false;
}
Cita:<script language="javascript">No te olvides de poner al formulario name="miformulario" y id="miformulario"
$(document).ready(function() {
$('#form, #fat, #miformulario').submit(function() {
$.ajax({
type: 'POST',
url: $(this).attr('action'),
data: $(this).serialize(),
success: function(data) {
$('#resultado').html(data);
}
})
return false;
});
})
</script>
Cita:<div id="resultado"></div>y al mandar el formulario se envia por ajax y actualiza eso.. otra cosa en upload.php en vez de regresar el dato como lo haces osea asi:
if(blablabla)
{
$status = XXXX
}
if(blablabla)
{
$status = XXX
}
return $status
if(blablabla)
{
echo 'TU MENSAJE';
return false;
}
if(blablabla)
{
echo 'TU MENSAJE';
return false;
}
<?php
define("IN_MYBB", 1);
require_once "project/global.php";
$status = "";
if ($_POST["action"] == "upload")
{
// obtenemos los datos del archivo
$tamano = $_FILES["archivo"]['size'];
$tipo = $_FILES["archivo"]['type'];
$archivo = $_FILES["archivo"]['name'];
$prefijo = substr(md5(uniqid(rand())),0,16);
if(!is_uploaded_file($_FILES['archivo']['tmp_name']))
{
echo 'Error al subir la imagen';
return false;
}
else
{
if(!preg_match("#^(gif|jpg|jpeg|jpe|bmp|png)$#i", strtolower(mb_substr(strrchr($_FILES["archivo"]['name'], "."), 1))))
{
echo 'Archivo con extensión no valida.';
return false;
}
else
{
$ext = substr(strrchr($archivo, '.'), 1);
$path = "_" . $prefijo . "." . $ext;
$destino = "files/" . $path;
$moveimg = @move_uploaded_file($_FILES['archivo']['tmp_name'], $destino);
if(!$moveimg)
{
echo 'No se a podido cargar la imagen.';
return false;
}
else
{
$insertarray = array(
'name' => $archivo,
'path' => $path,
'type' => $tipo,
'size' => $tamano,
'regupload' => TIME_NOW
);
$db->insert_query("imgupload", $insertarray);
$status = "Archivo subido: <b>".$archivo."</b>";
}
}
}
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>PHP upload - unijimpe</title>
<link href="estilo.css" rel="stylesheet" type="text/css" />
<script language="javascript">
$(document).ready(function()
{
$('#imgupl').submit(function()
{
$.ajax({
type: 'POST',
url: $(this).attr('action'),
data: $(this).serialize(),
success: function(data)
{
$('#resultado').html(data);
}
})
return false;
});
})
</script>
</head>
<body>
<table width="413" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="413" height="40" class="titulo">PHP upload - unijimpe </td>
</tr>
<tr>
<td class="text">Por favor seleccione el archivo a subir:</td>
</tr>
<tr>
<form action="upload.php" name="imgupl" id="imgupl" method="post" enctype="multipart/form-data">
<td class="text">
<input name="archivo" type="file" class="casilla" id="archivo" size="35" />
<input name="enviar" type="submit" class="boton" id="enviar" value="Upload File" />
<input name="action" type="hidden" value="upload" /> </td>
</form>
</tr>
<tr>
<td class="text" style="color:#990000"><div id="resultado"></div></td>
</tr>
<tr>
<td height="30" class="subtitulo">Listado de Archivos Subidos </td>
</tr>
<tr>
<td class="infsub">
<?php
$getimages = $db->simple_select('imgupload', '*', '', array('order_by' => 'regupload', 'order_dir'=>'ASC'));
echo "<ul>";
while($image = $db->fetch_array($getimages))
{
$user = get_user($image['uid']);
echo "<li><a href=\"files/" . $image['path'] . "\" class=\"linkli\">" . $image['path'] . "</a> | " . $user['username'] . "</li>\n";
}
echo "</ul>";
?> </td>
</tr>
</table>
</body>
</html>
<?php
define("IN_MYBB", 1);
require_once "project/global.php";
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>PHP upload - unijimpe</title>
<link href="estilo.css" rel="stylesheet" type="text/css" />
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script language="javascript">
$(document).ready(function()
{
$('#imgupl').submit(function() {
{
$.ajax({
type: 'POST',
url: $(this).attr('action'),
data: $(this).serialize(),
success: function(data)
{
$('#resultado').html(data);
}
})
return false;
});
})
</script>
</head>
<body>
<table width="413" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="413" height="40" class="titulo">PHP upload - unijimpe </td>
</tr>
<tr>
<td class="text">Por favor seleccione el archivo a subir:</td>
</tr>
<tr>
<form action="upload.php" name="imgupl" id="imgupl" method="post" enctype="multipart/form-data">
<td class="text">
<input name="archivo" type="file" class="casilla" id="archivo" size="35" />
<input name="enviar" type="submit" class="boton" id="enviar" value="Upload File" />
<input name="action" type="hidden" value="upload" /> </td>
</form>
</tr>
<tr>
<td class="text" style="color:#990000"><div id="resultado"></div></td>
</tr>
<tr>
<td height="30" class="subtitulo">Listado de Archivos Subidos </td>
</tr>
<tr>
<td class="infsub">
<?php
$getimages = $db->simple_select('imgupload', '*', '', array('order_by' => 'regupload', 'order_dir'=>'ASC'));
echo "<ul>";
while($image = $db->fetch_array($getimages))
{
$user = get_user($image['uid']);
echo "<li><a href=\"files/" . $image['path'] . "\" class=\"linkli\">" . $image['path'] . "</a> | " . $user['username'] . "</li>\n";
}
echo "</ul>";
?> </td>
</tr>
</table>
</body>
</html>
<?php
define("IN_MYBB", 1);
require_once "project/global.php";
$tamano = $_FILES["archivo"]['size'];
$tipo = $_FILES["archivo"]['type'];
$archivo = $_FILES["archivo"]['name'];
$prefijo = substr(md5(uniqid(rand())),0,16);
if(!is_uploaded_file($_FILES['archivo']['tmp_name']))
{
echo 'Error al subir la imagen';
return false;
}
if(!preg_match("#^(gif|jpg|jpeg|jpe|bmp|png)$#i", strtolower(mb_substr(strrchr($_FILES["archivo"]['name'], "."), 1))))
{
echo 'Archivo con extensión no valida.';
return false;
}
$ext = substr(strrchr($archivo, '.'), 1);
$path = "_" . $prefijo . "." . $ext;
$destino = "files/" . $path;
if(!$moveimg)
{
echo 'No se a podido cargar la imagen.';
return false;
}
if($_FILES["archivo"]['error'])
{
@unlink($destino);
echo 'error';
return false;
}
$insertarray = array(
'name' => $archivo,
'path' => $path,
'type' => $tipo,
'size' => $tamano,
'regupload' => TIME_NOW
);
$db->insert_query("imgupload", $insertarray);
echo "Archivo subido: <b>".$archivo."</b>";
return false;
?>