I'm sure this is easy for many of you, but I'm only just starting out with using PHP so I'm not sure where to go from here. Anyway, my problems/tasks are as follows:
- I have a form which both adds information to MySQL, and uploads a file. The file uploading works, but the way I have it working, it gives all uploaded files a JPG extension. I'd like to retain the extension of the original file.
- The uploaded file uses a name taken from one of the other form fields. This is purely so that I can later display the appropriate image (on another page of my site). Instead, I'd like to be able to rename the file based on some abbreviations, and then a number which is today's date (eg my file might end up like this: "DJ-11.05.05" (being short for "Disc Jockey", uploaded on 11th May 2005).
I did hunt around these forums for existing code but couldn't find quite what I was looking for/wasn't sure exactly how to implement it.
Below is my code:
Code: Select all
<FORM ENCTYPE="e;multipart/form-data"e; ACTION="e;<? $PHP_SELF ?>"e; METHOD="e;POST"e;>
<strong>Name:</strong><br>
<INPUT type="e;text"e; name="e;name"e; size="e;40"e;><br><br>
<strong>Website:</strong><br>
http://<INPUT type="e;text"e; name="e;website"e; size="e;50"e;><br><br>
<strong>Type:</strong><br>
<select name="e;type"e;>
<option selected>Band</option>
<option>Label</option>
<option>Site</option>
</select><br><br>
<strong>Short Description:</strong><br>
<INPUT type="e;text"e; name="e;description"e; size="e;78"e;><br><br>
<strong>Banner / Logo:</strong><br>
<INPUT type="e;file"e; name="e;fnt"e; size="e;78"e;><br><br>
<input type="e;submit"e; name="e;enter_data"e; value="e;Submit"e;></TD>
</form>Code: Select all
<?
if ($_POST['enter_data']) {
if ($fnt != "") {
$name = stripslashes($name);
copy($_FILES['fnt']['tmp_name'], "../images/ads/$name.jpg");
$resource = mysql_query("INSERT into sponsors (name, website, description, type, pic) VALUES ('$name', '$website', '$description', '$type', 'Y')") or die(mysql_error()); }
else {
$resource = mysql_query("INSERT into sponsors (name, website, description, type) VALUES ('$name', '$website', '$description', '$type')") or die(mysql_error()); }
MYSQL_CLOSE();
echo"<META HTTP-EQUIV=refresh content=0;URL=index.php>";
}
?>