JoannaBlatt / tomato-root-architecture

0 stars 0 forks source link

Upload button functionality #14

Closed JoannaBlatt closed 7 months ago

JoannaBlatt commented 8 months ago

Make the upload button save the user file to the arbor-reconstructions folder. After this is done the automated data processing script should be run. I think this would be more frontend, but we can discuss this more.

JoannaBlatt commented 8 months ago

So I'm trying some of the form code, but I'm having trouble getting it to redirect to the correct page. I have gotten it to set up the upload file functionality and that seems to work, but still trying to get it to save to a specific location. He doesn't seem to have the code easily accessible so I have to copy from the video

JoannaBlatt commented 8 months ago

found a different video that looks better for our purposes: https://www.youtube.com/watch?v=vBCU2Upno0c

I'm going to test it shortly after I watch a little more. The other had some backend I didn't want to deal with.

JoannaBlatt commented 8 months ago

https://www.theserverside.com/blog/Coffee-Talk-Java-News-Stories-and-Opinions/Ajax-JavaScript-file-upload-example This code seems like a reasonable starting place. Tried first pass and it has trouble finding the file "upload.php" that I had made but I'll work on that. Taking a break.

JoannaBlatt commented 8 months ago

Going to see if I can finally get the upload button to actually save the file somewhere.

JoannaBlatt commented 8 months ago

I still can't figure out why it's not seeing the upload.php file. I also can't tell if it's because of codespace or my code. I'll go ahead and commit a fork, but nothing in it really works.

JoannaBlatt commented 8 months ago

I'm going to look more into this now.

JoannaBlatt commented 8 months ago

I think we may need to make a server, or I need to be able to test on his server. Either way I'm not making much progress. Here are more things I was looking at: https://games.greggman.com/game/saving-and-loading-files-in-a-web-page/ https://www.youtube.com/watch?v=Zyjgc2bySZo&list=PLDlttLRccCk5sv4buRYqXnGU6M1KKkq-4&index=2 https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API https://docs.github.com/en/codespaces/developing-in-a-codespace/forwarding-ports-in-your-codespace

JoannaBlatt commented 8 months ago

going to mess around and see what I can figure out with this. It feels like I'm missing something easy.

JoannaBlatt commented 8 months ago

looking into console log. Mostly been trying to figure out why it's giving the 404 when the file is right there

JoannaBlatt commented 8 months ago

Looking into how to run a php website on codespace. Resources: https://www.youtube.com/watch?v=4Ol6X2VJlfw https://www.youtube.com/watch?v=_dfLOzuIg2o

JoannaBlatt commented 8 months ago

I don't want to have to use all these other things, and I'm sure I've run basic php without them. I can't find my older projects currently though (they're on buzz and I no longer have access). I feel like I keep being redirected to use software I shouldn't need to. I'm going to try and find the most basic php website example or see if I can't get access or find copies of my old projects to look at.

JoannaBlatt commented 8 months ago

For some reason I have trouble finding a simple example that doesn't involve anything extra. I know they're out there. Everything it just going through lots of extra setup that we don't need to mess with.

JoannaBlatt commented 8 months ago

I'm trying to make a very simple php/html website for testing the most basic of functionality. I will probably create a repo and share it.

JoannaBlatt commented 8 months ago

I feel like this isn't the right path as setting up php is proving more troublesome than expected. Would love to know what setup Dr. C currently has so I can just work off of that.

JoannaBlatt commented 7 months ago

after messing around with some things I had tried before, they still aren't working on Dr. C's server so I'm looking into it more

JoannaBlatt commented 7 months ago

Looking into this: https://code-boxx.com/create-save-files-javascript/

JoannaBlatt commented 7 months ago

Trying again

JoannaBlatt commented 7 months ago

I tried copying the stuff in blob, but it didn't work so I'm going to try and look around Can debug using console log and f12 to access devtools / inspect page Can directly go to the php file by typing it into the url It looks like it might have something to do with permissions in .htaccess file I'm looking into that now. Because I can access the php files manually and they will run so php is working correctly. The files are coming up as 404 not found so based on searches it looks like this is the problem. Reading https://help.dreamhost.com/hc/en-us/articles/216456227--htaccess-overview now.

JoannaBlatt commented 7 months ago

downloaded filezilla and looking at .htaccess documentation to see if I can understand it

JoannaBlatt commented 7 months ago

saved the original to the google drive for when I start editing it. Trying to quickly learn this.

JoannaBlatt commented 7 months ago

I really don't want to mess with permissions without discussing with Dr. C first. Getting ftp access would also be good. Not sure why it wasn't working.

I'm looking into ways that don't involve a separate php file. resource: https://stackoverflow.com/questions/29496603/js-saving-uploaded-file-do-disc

JoannaBlatt commented 7 months ago

Looking into this now: https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage

JoannaBlatt commented 7 months ago

Got a testing page setup and it does seem to work, I just need to understand this more so I can access it through the backend I've created.

I really think I'm going to need to change permissions to get this to work. Doing web storage saves it to the client side, and that will cause issues if I can't send info to the server side. And if it can't see the .php files will it even have access to the python files?

JoannaBlatt commented 7 months ago

Can access python files and try to run them using So some access it possible. Still not sure how to pass a parameter

I managed to save something on the server side but it created a second backend file or something that I couldn't seem to access in any way so I removed both backend and readded the directory

JoannaBlatt commented 7 months ago

I think setting up the requirements for backend and just testing through command line, then working on this again might be good.

JoannaBlatt commented 7 months ago

So I can access the php file, but it doesn't seem like I'm actually sending anything to it, so I'm looking into that now. Trying to clean up the files so it's more manageable.

JoannaBlatt commented 7 months ago

I managed to get a 418 error. I can see that it does get the file, and then passes the file into the javascript function. But it doesn't seem to end up in the php file. Not sure why yet.

JoannaBlatt commented 7 months ago

Seeing if I can just do this with forms. But my head is hurting so I may put it away for now. Currently reading about how the fetch api works here: https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch And modifying upload files to see if it actually saves the file if I just pass it through a form.

JoannaBlatt commented 7 months ago

Looking into where I left off on this.

JoannaBlatt commented 7 months ago

It seems like I'm going in circles. I can send the file it looks like, but then when I try to save it somewhere it doesn't seem to work.

JoannaBlatt commented 7 months ago

can get the file name by accessing in php using $fname = getRequestData("testingfileupload"); But this seems to be a string? However I am using the file type. So I'm not sure what is going on.

using the first reply to this: https://stackoverflow.com/questions/43307467/saving-data-from-html-form-on-server I was able to save a file to the server. So that's something. I just wanted to be able to save something somewhere. I'm just having touble either accessing or sending an actual file. I'm not quite sure why yet.

JoannaBlatt commented 7 months ago

This retrieves the name of the file: echo $_FILES["testingfileupload"]["name"]; Still trying to figure out why move_uploaded_file isn't working.

JoannaBlatt commented 7 months ago

I feel like I'm getting closer. It is obviously sending information about the file. I'm going to see if I can find some debugging tools on https://www.php.net/manual/en/features.file-upload.php and https://www.php.net/manual/en/features.file-upload.common-pitfalls.php since it seems like the issue is definitely with move_uploaded_file(). I can see the input strings, so I know they aren't null. But I'm not quite sure why it's failing. Something to test later.

JoannaBlatt commented 7 months ago

While waiting to hear from Dr. C. I'm working on this using some code from the php file-upload page to see if I can find where things are going wrong.

JoannaBlatt commented 7 months ago

stat lets you see permissions of the directory. Probably works for files too. Thought I had managed to save a file to the temp folder, but was unable to replicate so must have been mistaken. Still not sure why it's unable to move the file.

JoannaBlatt commented 7 months ago

Since I've had success saving a file to the server and calling a script from php I will try and implement this with the actual files and code we need to use.

JoannaBlatt commented 7 months ago

finished moving files and trying to get paths to work correctly again.

JoannaBlatt commented 7 months ago

Upload button now can save a file to the server. I also incorporated the HTML page layout. It just needs to be refined and applied to the main page.

JoannaBlatt commented 7 months ago

can now save to the server so this seems properly functional.