Here are some of the things I've been working on:
Uploading Files
The first thing I did was create a form. The form posts to an external php file, collects inputted data about the file and there is a field that allows you to select a file (type:"file"). Here's the code I used to upload the file to the folder on the server:
$file = ($_FILES['uploaded']['name']);
/*upload*/
$target = "upload/";
$target = $target . basename( $_FILES['uploaded']['name']) ;
$ok=1;
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
{
The other main task was to add the data to the database:
$name = $_REQUEST['name'] ;
$tags = $_REQUEST['tags'] ;
$submittedby = $_REQUEST['submittedby'] ;
$file = ($_FILES['uploaded']['name']);
$level=serialize($_POST['level']);
$type=serialize($_POST['type']);
mysql_query("INSERT INTO Resources
(name, tags, level, type, url, submittedby) VALUES(' $name ', ' $tags ', ' $level ', ' $type ', '$file', '$submittedby') ")
or die(mysql_error());
echo "Data Inserted!";
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
}
else {
echo "Sorry, there was a problem uploading your file.";
}
if ($uploaded_type =="text/php")
{
echo "No PHP files<br>";
$ok=0;
}
... Just don't forget to connect to mySQL first.
No comments:
Post a Comment