save data to DB in the new index.php #957
Comments
Hi, This is how I managed to add uploaded files to a DB, with no "SyntaxError" outputs. First, add those two functions in the "php/index.php" (latest version of the script) file:
ALSO, you need to add a line in the "handle_file_upload" function, at the end, BEFORE the last ELSE statement, BEFORE the close-bracket of "if (!$error && $file->name) {" (after "$file->delete_type = 'DELETE';") - the line you have to add is "$file->upload_to_db = $this->add_img($file->name);" Both variables do not need escaping because it is not an user input - please correct me if I'm wrong. Hope it helps, Greets! |
Hello, Thanks |
Please upload the code so I can take a look :) |
Hello, |
Hello again, $this->user_name = $_SESSION['user_name']; // I used the following in order to add the pics to a certain user which was previously set with session on login Do you have a session with the name 'user_name' set? If not, remove that line and just let the next one. If yes (--remove the second line if you want the variable to be equal to whichever the session returns), have you added "session_start();" at the beginning of the index.php file, right after the php open tag? Issues like those may trigger a syntax error imo. Tell me whether this solved the issue! Greets! :) |
Hello, Thanks again :) |
Yes :) Np, I'm glad that it worked :) |
Hello Danciu, Thank you very much |
Hi again :) There is a "download" table in the html file in which I removed the Delete button and such, leaving only the file name (you can also leave the thumb - I didn't use that functionality so it had no point for me), size and an "uploaded" message. I didn't modify the files in the script furthermore to avoid serious headaches. So, after the script tables (both upload and download), I created a div which is set to visible with jquery after the upload is complete (... Need further help? Greets! |
I am sorry, I could not follow you here. actually I want to use the same interface that jquery has, its good UI and I want to stick to it and by default just show the images by making DB query and showing the records. After this I will customize the delete function too and delete record from DB and then unlink file. For now, I tried to customize the get() function from php/index.php and I did something like this using DB class I have made:- but it does not show anything by default. I did extended my DB class to the "UploadHandler" |
shouldn't you have modified the post function instead? anyway, most of the php in there is json-encoded, do you really prefer getting headaches instead of creating a small php script + jquery function(s) that will work with the upload script? |
I can completely understand what you are saying must be correct, but since I am new to this, so asking such silly questions. Okay, so you are saying that I should change the code of post function and the json that it returns is the json code that it displays after file upload.. right? and in this place I can do the select query and fetch records and put them in json format and just return... am I right? |
that was just a wild guess, I don't know exactly whether it's that, something else or even something in the JS file - I haven't had the time to go that far, especially that I'm not a JSON expert so I commented some of the index.php file and created my own php that reads the uploaded files and my own jquery script that hides the current pic DIV on delete, refreshes the main div on picture upload etc. Now that I go through index.php, I see that I commented the following function:
also, the get_file_object function. Try working around those two first and see what you'll get (imo, a LOT of JSON errors GRIN) |
sansphp, I read that you had managed to insert data for each image in mysql. thanks |
Hi Chaudx, Sure, I will send you detailed reply in about 12hours. |
thanks, i look forward |
Hi Chaudx, To also insert the description with each image I made below mentioned changes:- I hope this helps. Feel free to let me know if I can help in any other way. I will try to be as quick as I can |
Hi sansphp: thank you very much |
Thank you, I am happy it worked for you. |
hello you can send me your code? becuase i work so hard so many days to do that but unsuccessful |
Hello Vourexx, Let me know if I can help in any other way. |
So now that we know how to save additional details but I am unable to find the way to show those additional details while loading images from database. Showing additional details of the image like Title that user gave to the image, category that user selected, etc. Please help. Thanks |
Hi Sunny, You are great... Thanks a billion. Sabatorio |
Hi Sabatorio, |
can any one customised it for joomla... ? |
thanks danciu888 for the code, i have successfully link and store uploaded file data into my database. i have one problem left which is if i click on the delete button, except that the uploaded file being deleted, i also want it to be deleted off from the database respectively (depend on which file that i delete in random) thanks in advanced |
Hello,
I've read all the previous issues about saving data to sql and json errors, I've also read the numerous harsh replies that were given such as "the script was not intended for that" and so forth;
however,
I simply wanted to save into a DB the name of the uploaded pic, but every bit of PHP code I added to "index.php" (which handles the form) turned into a "SyntaxError: Unexpected token". I tried adding the code in the "handle_file_upload" function, at its end, just before returning the file object.
I would be really grateful if someone helped me, even though the script was intended for "enhancing the client-side file upload".
Thank you a million!
The text was updated successfully, but these errors were encountered: