PDA

View Full Version : Upload Script



fEaRdArEaPeR
07-12-2005, 03:38 PM
I need a script to enable user to upload files onto my webspace.

Please Help.

~ fEaR

angst
07-12-2005, 03:46 PM
i'm using this script,, seems to work pretty well..

upload.php script:



<html>
<head><title>Upload Details</title></head>
<style type="text/css">
<!--
.style3 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; }
-->
</style>

<?

//MySQL DB Info:

$DBhost = "localhost";
$DBuser = "root";
$DBpass = "sql";
$DBName = "pictures";


$save_path="C:\\Program Files\\Apache Group\\Apache2\\htdocs\\pics\\images\\";


$file = $_FILES['userfile'];
$k = count($file['name']);


for($i=0 ; $i < $k ; $i++)
{


$FileName = $file['name'][$i];
$FileSize = $file['size'][$i];

if(isset($save_path) && $save_path!="")
{
$name = split('/',$file['name'][$i]);

move_uploaded_file($file['tmp_name'][$i], $save_path . $name[count($name)-1]);
}

}

if(! isset($save_path) || $save_path =="")
{
echo 'Files have not been saved, please edit upload.php to match your configuration';
}


?>
</table>



<form action="func.php?func=addpic" method=post>
<table width="698" border="0" cellspacing="0" cellpadding="0">
<tr>
<th width="160" scope="row"><span class="style3">Gallery </span></th>
<td width="538">


<select name="PicSection">
<?
$link = mysql_connect($DBhost, $DBuser, $DBpass) or die('Login details incorrect');
$db_selected = mysql_select_db($DBName, $link) or die('Database name incorrect');

$result = mysql_query('SELECT * FROM picsections');

while ($rows = mysql_fetch_array($result))
{

$Sid=$rows[0];
$SecName = $rows[1];
echo "<option value=$Sid>$SecName</option>";
}
mysql_close($link);




?>
</select>



</td>
</tr>
<tr>
<th width="160" scope="row"><span class="style3">File name </span></th>
<td width="538"><input type=text name="PicName" value="<? echo $FileName; ?>" readonly></td>
</tr>
<tr>
<th width="160" scope="row"><span class="style3">File Size </span></th>
<td width="538"><input type=text value="<? echo $FileSize; ?>" readonly></td>
</tr> <tr>
<th scope="row"><span class="style3">Picture Title </span></th>
<td><input type=text name="PicTitle"></td>
</tr>
<tr>
<th scope="row"><span class="style3">Description</span></th>
<td><textarea cols="50" rows="6" name="PicDesc"></textarea></td>
</tr>
<tr>
<th scope="row">&nbsp;</th>
<td><input type=submit></td>
</tr>
</table>
</form>


</body>
</html>





uploadform.php



<html>
<head><title>File Upload Tester</title></head>
<body>

<form enctype="multipart/form-data" action="upload.php" method="post">

<table border="0" cellpadding="10" align="center" width="770" align="center">
<tr><td align="center"><font size=3 face=verdana>File Upload Test</font></td></tr>

<tr>
<td valign="top" align="center">
<table border=0 align="center" cellpadding=3>
<tr><td><input type="file" name="userfile[0]"></td></tr>
<tr><td colspan=2 align="center">
<input type="hidden" name="sessionid" value="<?= $sid ?>">
<input type="submit" value='Upload!'>
</td></tr></table>
</td>
</tr>
<tr><td>
</table>


</form>

</body>
</html>




hope that helps.

-Ken

fEaRdArEaPeR
07-12-2005, 04:14 PM
and one more thing.

i have cpanel installed on my webspace.

how can i create a SQL database with the name and pass that i want.

delinear
07-12-2005, 04:26 PM
If you want to do it through the cpanel, you probably have phpMyadmin on there somewhere. That will allow you to access and manipulate your databases manually.