I need some help working through this. I have an uploader for files, but I'd like it to create a link of the file uploaded and automatically post it to a page. Each user has a profile page and I'd like these pictures to be posted to their profile page. I guess with a session, it would take the logged in username and post the pictures uploaded on the page " member_profile2.php?username=xxxx "
Here is my upload file for reference.
uploads.php
<?php
$Dir = "temporary";
if (isset($_POST['upload'])) {
//if file uploaded
if (isset($_FILES['new_file'])) {
//if successful
if (move_uploaded_file($_FILES['new_file']['tmp_name'], $Dir . "/" . $_FILES['new_file']['name']) == TRUE){
chmod($Dir . "/" . $_FILES['new_file']['name'], 0644);
echo "<b>File \"" . htmlentities($_FILES['new_file']['name']) ." was successfully uploaded </b><br />\n";
//displays file info
echo "Name: ". htmlentities($_FILES['new_file']['name']) . "<br />".
"Size: " . $_FILES['new_file']['size'] . " bytes" . "<br />".
"Type: " . $_FILES['new_file']['type'];
}
//if not successful
else {
echo "<b>Uploading \"" . htmlentities($_FILES['new_file']['name']) . " was unsuccessful</b><br />\n";
}
}
}
?>
<form action="uploads.php" method="POST" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="250000" /><br />
Select file to upload:<br />
<input type="file" name="new_file" />
250kB limit!<br />
<input type="submit" name="upload" value="Upload File" /><br />
</form>
?>
and my member_profile2.php
<?php /*?><?php error_reporting(E_ALL ^ E_NOTICE); ?><?php */?>
<?php
# Starting the session
session_start();
# Requiring SQL connection
require_once 'mysql-connect2.php';
# Setting auser as SESSION['user']
$auser = $_SESSION['user'];
# SQL protecting variables
$username = (isset($_GET['username']))?mysql_real_escape_string($_GET['username']):$username;
# Checking through each query
if(isset($auser)) {
$sql = mysql_query("SELECT * FROM `user` WHERE `username` = '$username'");
if(mysql_num_rows($sql)) {
while($row = mysql_fetch_array($sql)) {
$page = "<h1>User Info</h1>".
"<b>Username: {$row['username']}<br /><br />".
"<b>First Name: {$row['firstname']}<br /><br />".
"<b>Last Name: {$row['lastname']}<br /><br />".
"<b>Email: {$row['email']}<br /><br />".
"<form name=\"backlistfrm\" method=\"post\" action=\"members2.php\">".
" <input type=\"submit\" value=\"Back to The List\">".
"</form><br />";
}
} else {
$page = "ERROR: No member found for username: <strong>{$_GET['username']}</strong>.";
}
} else {
$page = "ERROR: Not logged in.";
}
# Printing the final output
print $page;
?>
I'd like the pictures to be displayed after the user details.
Any help with this would be great.
I was also thinking, could I just have the uploader save it as a filename with the user's username? For example, "user1-image1.jpg". And then have their profile page pull and display any files with the name user1-image1-10.jpg (10 being max possible uploads for that user).
How would I do this? This sounds maybe easier.