Upload af billede tilknyttet bruger id
Hej EksperterJeg har en php side:
<?php require_once('include/db.inc.php');
?>
<?php include('blogHeader.php'); ?>
<td valign="top">
<h1>New Blog Post</h1>
<p>Please use this form to post a new blog entry</p>
<form method="post" action="newEntryResponse.php">
<input type="hidden" name="action" value="newEntry">
<table width="300">
<tr>
<th>Fornavn</th>
<td><input name="fornavn" type="text" id="fornavn"></td>
</tr>
<tr>
<th>Efternavn</th>
<td><input name="efternavn" type="text" id="efternavn"></td>
</tr>
<tr>
<th> </th>
<td><input type="submit" name="Submit" value="Submit Post"></td>
</tr>
</table>
</form>
</td>
<?php include('blogFooter.php'); ?>
som sender input til min db ved hjælp af denne php fil:
<?php require_once('include/db.inc.php');
$newPostCmd = $blogDB->newAddCommand('webindmeld');
$newPostCmd->setField('fornavn',POST('fornavn'));
$newPostCmd->setField('efternavn',POST('efternavn'));
$newPost = $newPostCmd->execute();
if(FileMaker::isError($newPost)) {
die('Database Error: '.$newPost->getMessage());
}
?>
<?php include('blogHeader.php'); ?>
<td valign="top">
<h1>Success</h1>
<p>Your post was made succesfully, please go back to the
<a href="index.php">home page</a> to see it.</p>
</td>
<?php include('blogFooter.php'); ?>
Derudover har jeg en formular som uploader et billede til en given mappe og omdøber billedet. Til det bruger jeg denne php form action:
<?php
// Your file name you are uploading
$file_name = $HTTP_POST_FILES['ufile']['name'];
// random 4 digit to add to our file name
// some people use date and time in stead of random digit
$random_digit=rand(0000,9999);
//combine random digit to you file name to create new file name
//use dot (.) to combile these two variables
$new_file_name=$random_digit.$file_name;
//set where you want to store files
//in this example we keep file in folder upload
//$new_file_name = new upload file name
//for example upload file name cartoon.gif . $path will be upload/cartoon.gif
$path= "uploads/".$new_file_name;
if($ufile !=none)
{
if(copy($HTTP_POST_FILES['ufile']['tmp_name'], $path))
{
echo "Successful<BR/>";
//$new_file_name = new file name
//$HTTP_POST_FILES['ufile']['size'] = file size
//$HTTP_POST_FILES['ufile']['type'] = type of file
echo "File Name :".$new_file_name."<BR/>";
echo "File Size :".$HTTP_POST_FILES['ufile']['size']."<BR/>";
echo "File Type :".$HTTP_POST_FILES['ufile']['type']."<BR/>";
<?php echo $file['name']; ?>
}
else
{
echo "Error";
}
}
?>
<?php
if(!isset($_FILES['userFile'])) die('No file was selected for uploading');
if($_FILES['userFile']['error'] != 0) die('File upload error '.$_FILES['userFile']['error']);
$file = $_FILES['userFile'];
move_uploaded_file( $file['tmp_name'], 'uploads/'.$file['name']);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Uploading a File</title>
</head>
<body>
<p>Thank you for uploading your file, <a href="uploads/<?php echo $file['name']; ?>">See the file</a></p>
</body>
</html>
1. Jeg kunne godt tænke mig at tilknytte det uploadede billede til id på den bruger jeg opretter ved hjælp af den første formular.
2. Jeg kunne godt tænke mig at starten af navnet på billedet får id nummeret på brugeren i stedet for et autogenereret nummer.
Jeg håber det giver mening og at nogen kan hjælpe.
Mvh Rasmus