I responded 2hr ago but comment did not show up. It happens all the
time. :-(
Here is it a again and hope it shows up.
def upload():
return
dict(form=crud.create(db.uploadedFiles,message='Successful
upload',next=URL()))
On Jun 8, 8:49 am, Web2py Newbie
<[email protected]> wrote:
> I want to expose a method which will accept a file POSTed to it and
> save the file to the database. I have found php examples all over the
> place (one below).
>
> How do i do this in web2py? I don't want to use a form as I don't
> want to upload interactively.
>
> My model is this:
> db.define_table('uploadedFiles',
> Field('displayName'),
> Field('store_file','upload',autodelete=True))
>
> Thanks in advance
>
> Brendan
>
> Example php:
> <input type="submit" value="Upload File" />
> </form>
> <?php
> $to_file = "tmp/" . basename($_FILES['uploadedfile']['name']);
> $from_file = $_FILES['uploadedfile']['tmp_name'];
>
> if (move_uploaded_file($from_file, $to_file)) {
> echo "Successful upload";
> ?>
> <a href="<?php echo $to_file;?>"><?php echo $to_file;?></a>
> <?php
> } else {
> echo "Unsuccessful upload";
> }
> ?>