I'm building several forms where I need to upload files to a directory and save the file name of the uploaded file to a mysql database. I'm using PHP and have the latest KendoUI Complete build.
I thought I saw a tutorial on this but can't find it anywhere. So, can you please send or post an example in PHP/MYSQL of how to setup a file upload that uploads the file to a directory and saves the filename in the database?
I think this would be a great tutorial to post on the site docs....or better yet, build the functionality into the next release, in PHP, of course.
Thanks for the help and I'm looking forward to seeing how these Premium forums work. I love the idea!
Thanks,
Tony
6 Answers, 1 is accepted
We have an async upload demo in PHP on GitHub. It shows how to set up the basic save/remove handlers.
Although it doesn't deal with DB of any kind, it should make a good foundation.
Tsvetomir Tsonev
the Telerik team

Thanks for the reply, however, it does not help solve my problem at all. This php code only saves the file in a directory. I guess I thought that this new Premium Support forum was going to be more helpful in terms of actual support rather than pointing to examples that don't help solve problems.
In any case, I can write my own implementation. I just need to know how to access the uploaded file name in the php example page assuming one file at a time is uploaded, not multiple file uploads. For example in the code below from the save.php example file, is the file name contained in the $files variable? Or is it in the $name variable? I'll write the php code the update the DB once I know what variable holds the actual file name of the uploaded file. Better yet, can you provide a php example for a single file upload as well?
<?php
$fileParam = "files";
$uploadRoot = "uploads/";
$files = $_FILES[$fileParam];
if (isset($files['name']))
{
foreach ($files["name"] as $i => $name) {
$error = $files['error'][$i];
if ($error == UPLOAD_ERR_OK) {
$targetPath = $uploadRoot . basename($files["name"][$i]);
$uploadedFile = $files["tmp_name"][$i];
if (is_uploaded_file($uploadedFile)) {
if (!move_uploaded_file($uploadedFile, $targetPath)) {
echo "Error moving uploaded file";
}
}
} else {
// See http://php.net/manual/en/features.file-upload.errors.php
echo "Error code " . $error;
}
}
}
// Return an empty string to signify success
echo "";
?>
Thanks,
Tony
I refrained from giving specific DB-related code as it will depend on the specific method you use in your project - PDO, ORM ,etc.
Anyway, a simple example using PDO would look like this:
$stmt = $dbh->prepare("INSERT INTO FILES (name) VALUES (:name)");
$stmt->bindParam(':name', $targetPath);
$stmt->execute();
Note that the actual file name is available in $targetPath.
The example will work with one file as well.
Tsvetomir Tsonev
the Telerik team

Thanks! That's perfect, though I won't be using PDO. I really just needed to know that $tagetPath holds the file name for single and multi uploaded files. Now I can setup the update and delete routines for the uploaders.
Thanks and I'll post my example when it's done so you can have a complete demo for PHP.
Tony

Hello Prima,
I would suggest to check the example provided in the first post, which demonstrates how to configure the save/remove handlers. Regarding the saving of the file to DB, this is a general topic and I am sure many examples, demonstrating it, could be found.
Regards,Dimiter Madjarov
Telerik