I have a newuserscript where user register and post a URL to an image, but I want that user can upload files from their own computer instead.
newuser.php
<?
$id = id2code(0);
$datearray = getdate(time());
$minute = $datearray["minutes"] - 23;
if (strlen($message) > 0)
print $message;
?>
<form name=_theForm action=./ method=post><input type=hidden name=op value=save><input type=hidden name=id value="<? print($id); ?>"><? print $tablebg ?>
<input type=text name=uid value="" maxlength=30 size=16>
<INPUT TYPE=password NAME=pwd value="" maxlength=16 size=16>
<INPUT TYPE=password NAME=pwd_confirm value="" maxlength=16 size=16>
<input type=radio name=sex value=M checked>
<input type=radio name=sex value=F>
<input type=radio name=selfRating value=1
<input type=text name=url size=50 value="http://">
<input type=hidden name=opcode value="<? print($minute); ?>">
<INPUT TYPE=submit name=newUser value=" DONE ">
Function adduser is defined in prep.php:
function addUser($uid, $pwd, $pic, $sex, $self)
{
$sql = "insert into user (uid, pwd, url, sex, selfvote) values ('" . AddSlashes($uid) . "','" .
AddSlashes($pwd) . "','" . AddSlashes($url) . "','" . $sex . "'," . $self . ")";
$connection = mysql_pconnect(SQL_SERVER, SQL_UID, SQL_PWD);
mysql_select_db(SQL_DB, $connection);
mysql_query($sql);
$sql = "select * from user where uid='" . AddSlashes($uid) . "' and pwd='" . AddSlashes($pwd) . "'";
$query = mysql_query($sql);
$rows = mysql_num_rows($query);
if ($rows > 0)
{
$record = mysql_fetch_array($query);
return $record["id"];
}
return 0;
}
I have a upload script that works, it uploads the file and put the filename in the database, but I cant get it to work if put the upload script in to the signup script. Plz help!
upload script:
<?
define("SQL_SERVER", "localhost");
define("SQL_UID", "xxx");
define("SQL_PWD", "zz");
define("SQL_DB", "aa");
if ($_SERVER['REQUEST_METHOD']=='GET'){
?>
<form method="post" enctype="multipart/form-data">
File to Upload: <input type=file name=file><BR>
<input type=submit value="Upload">
</form>
<?
} else {
$tmp_loc = $_FILES['file']['tmp_name'];
$file = $_FILES['file']['name'];
move_uploaded_file($tmp_loc,"./_tmp/".$row['id'].".jpg");
//$tmp_loc=$_FILES['file']['tmp_name'];
//$name=$_FILES['file']['name'];
//move_uploaded_file($tmp_loc, "./_tmp/$name");
$errorList = array();
$count = 0;
if (!$tmp_loc) { $errorList[$count] = "Invalid entry: File"; $count++; }
if (sizeof($errorList) == 0) {
$connection = mysql_pconnect(SQL_SERVER, SQL_UID, SQL_PWD);
mysql_select_db(SQL_DB, $connection);
$query = "INSERT INTO user (picurl, datecreated) VALUES('$name', NOW())";
$result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());
echo "<font size=-1>Added successfully.</font>";
mysql_close($connection);
} else {
echo "<font size=-1>The following errors were encountered: <br>";
echo "<ul>";
for ($x=0; $x<sizeof($errorList); $x++)
{
echo "<li>$errorList[$x]";
}
echo "</ul></font>";
}
}
?>