Jump to content


This topic is now archived and is closed to further replies.


Simple Biography Script

Recommended Posts

Ok, so I'm working on a script, very simple, that uses four form elements. A file (image) upload, First name, Last name, and year (school year..freshman, sophomore, junior, senior). What I need to happen is for the first name, last name, year, and image name elements to be inserted into a mysql database. The image also needs to be uploaded, and the filename changed to essentially firstnamelastname.jpg (assuming it's a jpg file). I can get the file to upload, but it retains the original filename. I can get the form elements to post to the database (not a problem for me, just haven't written that part yet). So I need to figure out:

1. How to change the filename.
2. Check for a jpg image type.
3. If possible, avoid having to chmod a directory to 777 for all this to work.
4. Maybe a little security?

Here's what I've got so far, it's sloppy..I apologize:

// Set Upload Directory
$uploadtmpdir = '';
$uploaddir = '';

// Error Handling
ini_set ('display_errors', 1);
ini_set ('upload_tmp_dir','$uploadtmpdir');
error_reporting (E_ALL & ~E_NOTICE);

// Check for submission
if (isset ($_POST['submit'])) {
$writebio = "INSERT INTO park_bios (first_name, last_name, year) VALUES ('{$_POST['firstname']}', '{$_POST['lastname']}', '{$_POST['year']}')";

if (move_uploaded_file ($_FILES['thefile']['tmp_name'], "{$uploaddir}/{$_FILES['thefile']['name']}")) {
print ("<p>Your file has been uploaded</p>");
$writepic = "UPDATE park_bios SET pic='{$_POST['posttitle2']}', content='{$_POST['postcontent2']}', poster='{$_POST['poster2']}' WHERE news_id='{$_POST['enewsset']}'";

} else {

print ("<p>Your file could not be uploaded because: <b>");

switch ($_FILES['thefile']['error']) {
case 1:
print 'The file exceeds the upload_max_filesize setting in php.ini';
case 2:
print 'The file exceeds the MAX_FILE_SIZE setting in the HTML form';
case 3:
print 'The file was only partially uploaded';
case 4:
print 'No file uploaded';




<form action="uploadfile01.php" enctype="multipart/form-data" method="post">
<p>Upload a file using this form: <br /><br />
<input type="hidden" name="MAX_FILE_SIZE" value="500000" />
<input type="file" name="thefile" /><br /><br />
First Name: <input type="text" size="20" name="firstname" /><br /><br />
Last Name: <input type="text" size="20" name="lastname" /><br /><br />
<input type="submit" name="submit" value="Upload this file" />

Any suggestions? I've looked through some old topics on similar issues, but most of them make it more complicated than I think it needs to be.

Share this post

Link to post
Share on other sites
I am not sure if it will work, but for renaming the files maybe you should look into the built-in rename function: http://php.net/rename

Share this post

Link to post
Share on other sites
Oh, and this may help you with some of your other questions: http://www.developer.com/lang/php/print.php/1456041

Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.