0

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.

3
  • we need to see some code to be able to answer all of your questions, im sure the php script is required but the jquery script you use is maybe only a demo that redirects to another server and this is why you think it is working even tho you deleted the php script Commented Jul 20, 2013 at 19:47
  • this jquery uploader that is run in the client, probably opens a connection to a server that hosts the php file you got, yes you can edit that php and make it save the filename into the database Commented Jul 20, 2013 at 19:49
  • "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." Try changing action="upload.php" to action="", just for fun. Commented Jul 20, 2013 at 20:38

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

3 Comments

That's what I initially thought but upload.php doesn't appear to actually be called or do anything as I've tried amending it but to no avail. I've tried putting deliberate errors in that script and even deleting it but the uploader still functions as before. Which seems odd.
@davidjwest Oh, it (upload.php) gets "called" alright. Otherwise, your upload form wouldn't work. You'll have to figure out a way to use the upl variable in your favor, for use in a database. I'm sure you will find relevant information on Google. You'll have to implement the database insertion below echo '{"status":"success"}'; and above exit; (between those). It won't work outside of that.
@davidjwest Jotform actually has an MySQL section jotform.com/help/126-Form-to-MySQL - I found it after I "Googled" this > google.ca/…
1
$('#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.)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.