A JM Posted June 30, 2009 Share Posted June 30, 2009 I'm running into a slight problem trying to figure out how to allow my users to add additional files to my DB (link only). Currently when my page loads it reads the files in a particular (uploaded from another form) directory from the server and using the following script which works perfectly. $path = 'some path here'; $dir = dir($path); while($file = $dir->read()) { echo $file . ' - <a href="' . $path . $file . '">' . $file . '</a>'; } My problem is that I want to allow the user to upload additional files and I want the links to appear on the first page after they upload the new file(s). I'm trying to figure out how to make this work - should I redirect them to another page; use javascript or ajax or some other technology??? I could really use some expertise on this one I'm a bit out of my league here... Any help or suggestions would greatly be appreciated. Thanks. A JM, Quote Link to comment https://forums.phpfreaks.com/topic/164253-solved-multiple-file-upload-add-to-original-page/ Share on other sites More sharing options...
patrickmvi Posted June 30, 2009 Share Posted June 30, 2009 I think what you're saying is that you want the newest files to appear first? You can either keep track of when your files were uploaded in your DB and sort them that way or you can look through all of the files and use a function like filemtime to get the date/time the file was last modified and then sort the files using that value. For more info on filemtime - go to http://www.php.net/filemtime Quote Link to comment https://forums.phpfreaks.com/topic/164253-solved-multiple-file-upload-add-to-original-page/#findComment-866419 Share on other sites More sharing options...
A JM Posted June 30, 2009 Author Share Posted June 30, 2009 No sorry. I'm trying to figure out the process of how to allow a user to upload additional files to my page and refresh the page with the newly uploaded files, does that make it any clearer? Currently my page reads from a recordset and fills in some fields on a form - the end user has the capability to change these fields and then save the form with the new changes. I want to allow the user the capability to also add an additional file(s) to the DB. I think my confusion is coming from needing to use "Submit" to "Upload" the files and currently "Submit" is used for updating the DB record... Am I making any sense? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/164253-solved-multiple-file-upload-add-to-original-page/#findComment-866431 Share on other sites More sharing options...
patrickmvi Posted June 30, 2009 Share Posted June 30, 2009 Would you want those to be two separate things that a user could do on the same page, or would you want the one submit button to handle both? Quote Link to comment https://forums.phpfreaks.com/topic/164253-solved-multiple-file-upload-add-to-original-page/#findComment-866448 Share on other sites More sharing options...
A JM Posted June 30, 2009 Author Share Posted June 30, 2009 The user should be able to do both. What I've done to alleviate writing the actual file paths to the DB is that I've create a directory associated with the recordset and that is recorded in the DB, this allows the user to upload as many files as needed and each file doesn't need to be individually recorded in the DB. I found this example of uploading multiple files I'm just not sure how to implement the script with regard to PHP (http://the-stickman.com/web-development/javascript/upload-multiple-files-with-a-single-file-element/) The example appears to be "real time" updating the page which is what I'm looking for but I'm not sure how it would be implemented in my example. How do I use that with PHP?? I'm still looking for thoughts and ideas on how to be able to implement so I'm open.... Quote Link to comment https://forums.phpfreaks.com/topic/164253-solved-multiple-file-upload-add-to-original-page/#findComment-866514 Share on other sites More sharing options...
A JM Posted June 30, 2009 Author Share Posted June 30, 2009 I wanted to ask an additional question or add some additional comments. Would it be possible to do this in Iframes? When my page loads it runs a script to populate the existing files in the directory for this recordset associated with this user. $path = 'some path here'; $dir = dir($path); while($file = $dir->read()) { echo $file . ' - <a href="' . $path . $file . '">' . $file . '</a>'; } Can I use an Iframe to display the files in that directory and then use another Iframe for the file upload routine that would allow the end user to add additional files and then update the original Iframe with the new files that were just uploaded? I think that will do what I'm looking for... Can I simply use the variables/recordset fields from the SQL query that I am currently using on the main form to populate the Iframe instead or do I have to go about that differently and somehow pass the variable/recordset fields to the Iframe? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/164253-solved-multiple-file-upload-add-to-original-page/#findComment-866731 Share on other sites More sharing options...
A JM Posted July 1, 2009 Author Share Posted July 1, 2009 I've been trying to get the Iframe scenario going and I think this will work but am having problems passing a recordset field to the Iframe, can anyone help? My recordset field that I want to pass from the main form is: $row_rstocdetail['maxclaimnum'] <iframe src="file_list.php?ID=<?php $row_rstocdetail['maxclaimnum'] ?>" name="filelist_frame" width=835 height=60></iframe> On the Iframe page I have the following: <body> <?php $path = "../myfolder/" . $GET['ID'] . "/"; $dir = dir($path); while($file = $dir->read()) { echo '<a href="' . $path . $file . '">' . $file . '</a><br />'; }?> </body> Quote Link to comment https://forums.phpfreaks.com/topic/164253-solved-multiple-file-upload-add-to-original-page/#findComment-866821 Share on other sites More sharing options...
A JM Posted July 1, 2009 Author Share Posted July 1, 2009 I finally got it, with a little help from AlexWD..! In case anyone is interested. <iframe src="file_list.php?ID=<?php echo $colname_rstConfirm; ?>" name="filelist_frame" width="500" height="175" frameborder="0"></iframe> <body> <?php $path = "../claims/" . $_GET['ID'] . "/"; $dir = dir($path); while($file = $dir->read()) { if($file != '.' && $file != '..') echo '<a href="' . $path . $file . '">' . $file . '</a><br />'; }?> </body> Thanks for letting me vent. I've still got to work on file section but I think now that I can refresh a portion of the page without submitting the entire page I hope I can figure it out. A JM, Quote Link to comment https://forums.phpfreaks.com/topic/164253-solved-multiple-file-upload-add-to-original-page/#findComment-867031 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.