davidjwest
davidjwest

Reputation: 546

Getting Uploaded Image Name into a Database

I'm using this image uploader:

http://www.jotform.org/jquery/ajax-multi-file-upload-with-progress-bar/#more-291

It's jQuery/Ajax, while I have it working I know little about either language. I want to modify it so that the filenames of all uploaded files get put into a database.

The included upload.php file doesn't appear to work as I've deleted that and the uploader is still functioning. If that was required then I could quite easily write the required PHP to do the job.

One solution would be for a PHP file to be executed after the upload finishes, how can I do that?

Appreciate any help here.

<form id="upload" method="post" action="upload.php" enctype="multipart/form-data">
        <div id="drop">
            Drop Here

            <a>Browse</a>
            <input type="file" name="upl" multiple />
        </div>

        <ul>
            <!-- The file uploads will be shown here -->
        </ul>

    </form>

Edited above - this is the form that the upload uses, is there anyway I could use an "isset" to check it's been used, there's no submit button though.

The above code is what I've got on the page with the uploader on it, it doesn't seem to actually call the upload.php file.

Upvotes: 0

Views: 1507

Answers (2)

Oberst
Oberst

Reputation: 477

$('#upload').fileupload({

    // This element will accept file drag/drop uploading
    dropZone: $('#drop'),

    // This function is called when a file is added to the queue;
    {***SNIP***}

        });

        // Automatically upload the file once it is added to the queue
        var jqXHR = data.submit();
    },

The second to last line var jqXHR = data.submit(); is when it submits the form. That's the AJAX part of it. Since you deleted the upload.php file, it actually gives a 404. However, the code was poorly written and doesn't seem to alert you it cant reach said file.

Nonetheless, upload.php IS getting called, and IS being used. As someone else above suggested, you can extend that to get any details about the uploaded files you need. (And actually, I would put any logic before the echo. That echo is what tells the JavaScript everything is hunky-dorey.)

Upvotes: 1

juco
juco

Reputation: 6342

I've not used this file uploader before. Having looked at it though, upload.php is responsible for processing the file after upload.

If you look at this script:

if(move_uploaded_file($_FILES['upl']['tmp_name'], 'uploads/'.$_FILES['upl']['name'])){
    echo '{"status":"success"}';
    exit;
}

You can see that on successful upload, it moves the file to the included uploads directory. It's at this point that you could extend this script and save $_FILES['upl']['name'] to a database. You might want to look in to the possible PHP database extensions

Upvotes: 1

Related Questions