Hi all,
I'm trying to allow my users to upload a file, the URL of which is stored into my SQL database. Here is what I have so far:
<form enctype="multipart/form-data" id="oefenstof_upload" name="oefenstof_upload" method="POST" action="
<?php
echo $editFormAction;
$target_path = "_files/oefenstof/";
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path);
?>">
<input name="oefenstof_uploadedby" type="hidden" value="<?php echo $slusername ?>" />
<input name="oefenstof_date" type="hidden" value="<?php echo date("Y-m-d") ?>" />
<input name="oefenstof_url" type="hidden" value="<?php echo $target_path ?>" />
<input type="hidden" name="MAX_FILE_SIZE" value="2000000" />
Kies een bestand om te uploaden:
<input name="uploadedfile" type="file" /><br />
Geef dit bestand een titel:
<input name="oefenstof_title" type="text" /><br />
<input type="submit" value="Bestand uploaden" />
<input type="hidden" name="MM_insert" value="oefenstof_upload" />
</form>
</p>
The writing into the database is handled elsewhere on the page. However, I can get the correct URL, but I cannot get the filename into my database. Could you please tell me how I could do this?
Thanks,
Frank
Storing URL of an uploaded file into SQL database
Moderator: General Moderators
-
misterfranky
- Forum Newbie
- Posts: 4
- Joined: Wed Feb 06, 2008 3:17 am
- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact:
Re: Storing URL of an uploaded file into SQL database
It's likely the DB query portion we'll need to see - can you post the INSERT code?
-
misterfranky
- Forum Newbie
- Posts: 4
- Joined: Wed Feb 06, 2008 3:17 am
Re: Storing URL of an uploaded file into SQL database
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "oefenstof_upload")) {
$insertSQL = sprintf("INSERT INTO oefenstof (oefenstof_date, oefenstof_uploadedby, oefenstof_title, oefenstof_url) VALUES (%s, %s, %s, %s)",
GetSQLValueString($_POST['oefenstof_date'], "date"),
GetSQLValueString($_POST['oefenstof_uploadedby'], "text"),
GetSQLValueString($_POST['oefenstof_title'], "text"),
GetSQLValueString($_POST['oefenstof_url'], "text"));
Does this help?
$insertSQL = sprintf("INSERT INTO oefenstof (oefenstof_date, oefenstof_uploadedby, oefenstof_title, oefenstof_url) VALUES (%s, %s, %s, %s)",
GetSQLValueString($_POST['oefenstof_date'], "date"),
GetSQLValueString($_POST['oefenstof_uploadedby'], "text"),
GetSQLValueString($_POST['oefenstof_title'], "text"),
GetSQLValueString($_POST['oefenstof_url'], "text"));
Does this help?
- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact:
Re: Storing URL of an uploaded file into SQL database
"title" comes from $_POST['title'] - what you're looking for (I think) is "filename" from $_FILES['uploadedfile']['name'] - which I don't see being added to your database at all.
-
misterfranky
- Forum Newbie
- Posts: 4
- Joined: Wed Feb 06, 2008 3:17 am
Re: Storing URL of an uploaded file into SQL database
The url that is being written into the DB comes from the hidden input in the form:
<input name="oefenstof_url" type="hidden" value="<?php echo $target_path ?>" />
However, this only echoes the url of the file, not the filename itself. I'm trying to truncate the url and the filename into a variable that I can then write into the DB, but no luck so far!
<input name="oefenstof_url" type="hidden" value="<?php echo $target_path ?>" />
However, this only echoes the url of the file, not the filename itself. I'm trying to truncate the url and the filename into a variable that I can then write into the DB, but no luck so far!
- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact:
Re: Storing URL of an uploaded file into SQL database
Since the form has not yet been submitted, PHP doesn't have anything in either $_FILES or $_POST
-
misterfranky
- Forum Newbie
- Posts: 4
- Joined: Wed Feb 06, 2008 3:17 am
Re: Storing URL of an uploaded file into SQL database
Yes, that's true, but isn't the writing into the DB handled when the form has been submitted? Shouldn't there then be a value in $_FILES or $_POST?
Do you have a suggestion as to how I should handle this?
Thanks!
Do you have a suggestion as to how I should handle this?
Thanks!