Hola a todos, me da mucho gusto saludarlos y espero me puedan ayudar, estoy intentando hacer una aplicación para que los usuarios puedan subir un archivo al sevidor y ademas este se grabe en una base de datos mysql, les pongo el codigo que en otro web site encontre e intente meterle el codigo para que el nombre del archivo lo metiera en la base de datos, pero me sale un error que tambien se los pongo.
Mil felicidades por el Millon , y espero me puedan ayudar.
<?
$UPLOAD_PATH = "files/"; // directory on the server where are you going to upload files
// on Unix servers directories look like "/home/users/jack/files/"
// Don't forget about final slashes!!!
$UPLOAD_NUM = 1; // the number of upload fields
// display uploaded file list or errors during uploading
// and upload files
function displayUploadedList ()
{
global $UPLOAD_PATH,
$UPLOAD_NUM,
$HTTP_POST_FILES;
$buff = '';
$error = 0;
for ($i = 0; $i < $UPLOAD_NUM; $i++)
{
$name = $HTTP_POST_FILES["File$i"]['name']; // this is the real name of your file
$tmp = $HTTP_POST_FILES["File$i"]['tmp_name']; // this is the temporary name of your file in temporary
// directory on the server
if (!is_uploaded_file ($tmp)) // is this temporary file really uploaded?
continue;
$buff .= "<li><span class=Text><b>".$name."</b></span>";
if (!@move_uploaded_file($tmp, $UPLOAD_PATH."/".$name)) // move temporary file to your upload directory
$error = 1;
}
if (strlen ($buff) == 0)
{
?>
<span class=Warning>Select at least one file to upload.</span>
<?
return false;
}
else if ($error)
{
?>
<span class=Error>Some of selected files have not been uploaded.</span><br>
<span class=Text>Check existence of upload directory: <b><?=$UPLOAD_PATH?></b> and your permissions.</span>
<?
return false;
}
?>
<span class=Message>Los siguientes archivos se subieron satisfactoriamente al servidor</font></span>
<span class=Text><ul><?=$buff?></ul></span>
<?
//intentemos meter el nombre del archivo a la base de datos
include("localconex.php");
$link=Conectarse();
$link = "SELECT id FROM documentos WHERE name='".($HTTP_POST_FILES["name"])."'";
$result = mysql_query($link);
if($row = mysql_fetch_array($result))
{
echo "Error, Username escogido por otro usuario";
}
else
{
$link = "INSERT INTO `documentos` (`.$name.` ) VALUES (";
$link .= "'".($HTTP_POST_FILES["name"])."'";
$link .= ")";
mysql_query($link);
mysql_close();
}
//$usuario=$HTTP_POST_VARS["nombre"];
//$mail=$HTTP_POST_VARS["email"];
mysql_free_result($result);
//header("location:emails.php?u=$usuario&e=$mail");
exit();
?>
<?
return true;
}
// display upload form
// this is not interesting function ;-(
function displayUploadForm () // display upload form,
{
global $UPLOAD_NUM;
$tablePre = "
<table border=0 cellspacing=0 cellpadding=0>
<tr>
<td bgcolor=#C0C0C0 align=left valign=top>
<table border=0 cellspacing=1 cellpadding=3>
<tr>
<td class=TableHeader align=left valign=middle colspan=8 bgcolor=#C0C0C0>Upload form </td>
</tr>
<tr bgcolor=#FFFFFF>
<td class=TableHeader align=left valign=middle colspan=8 height=1></td>
</tr>
";
$displayed = '';
for ($i = 0; $i < $UPLOAD_NUM; $i++)
{
$displayed .= "<td class=TableElement bgcolor=#FFFFFF><input type=file name=File$i length=25></td></tr>";
}
$tableSuf = "
</table>
</td>
</tr>
</table>
<p><input type=submit name=Upload value=\"Subir Archivos\" style=\"font-size: 10pt;\"></p>";
print $tablePre.$displayed.$tableSuf;
}
?>
<html>
<head>
<title>Dialogo para subir archivos al servidor</title>
<link rel=stylesheet type=text/css href=./styles.css>
</head>
<body bgcolor="#FFFFFF" text="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table width="100%" height=100% border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="left" bgcolor="#C0C0C0">
<table width="100%" height=100% border="0" cellspacing="1" cellpadding="5">
<tr>
<td bgcolor="#C0C0C0" width="25" height=20> </td>
<td bgcolor="#FFFFFF" colspan=2>
<?
print "<font class=Text><b>Archivos a subir</b></font>";
?>
</td>
</tr>
<tr> <form method=POST enctype="multipart/form-data" action="./index.php" >
<td align="left" valign="top" bgcolor="#FFFFFF" width="25"> </td>
<td align="left" valign="top" bgcolor="#FFFFFF" height=100%>
<?
displayUploadForm ();
?>
</td>
<td align="left" valign="top" bgcolor="#FFFFFF" width="50%">
<?
if (isset ($Upload)) // if user has clicked on Upload button we must try to upload something
displayUploadedList ();
?>
</td>
</form>
</tr>
<tr>
<td bgcolor="#C0C0C0" colspan="2" height=20><span class=Text><b>Comments to: <a href=mailto:[email protected]>[email protected]</a></b></span></td>
</tr>
</table>
</tr>
</table>
</body>
</html>