AzeS Posted December 20, 2016 Share Posted December 20, 2016 (edited) I have a problem with a decision.... i want to give the user the opportunity to update his profile... so how do i get around this the smartest way ? i know how to, but not what the most effective way would be like... i thought about putting all in a function and running it via switch case or maybe for each item a function or update everything at once [edited img=https://media.giphy.com/media/YsTs5ltWtEhnq/giphy.gif] like : Exmp 1 func upic1($id) { sql do your magic thing ! } func upic2($id) { sql you holy wizard ! } func upic3($id) { sql trickshot ! } Exmp 2 func uallpics($stmt,$id) { Switch $stmt { case upic1 sql do your magic thing ! case upic2 sql you holy wizard ! case upic3 sql trickshot ! default sql overload !! } } Exmp 3 func uallpic($id){ sql overload !! } Edited December 20, 2016 by Barand remove irrelevant image Quote Link to comment https://forums.phpfreaks.com/topic/302789-what-is-more-practical/ Share on other sites More sharing options...
ginerjm Posted December 20, 2016 Share Posted December 20, 2016 (edited) Methinks you are looking at this oddly. Updating a profile - ie, modifying the contents of a form with various input fields - is a simple update process no different than any other. Give the users a link to a script that checks for proper authorization and then sends out a form and retrieves it via a POST and does the proper input validations and then does the update. Are you seeing this as anything different? PS - I find your choice of logo/avatar offensive. Edited December 20, 2016 by ginerjm Quote Link to comment https://forums.phpfreaks.com/topic/302789-what-is-more-practical/#findComment-1540584 Share on other sites More sharing options...
NotionCommotion Posted December 20, 2016 Share Posted December 20, 2016 (edited) It seems that your example 1 and example 2 provide the same UX where the user updates a single profile property, but example 3 updates all profile properties. Correct? If so, you should only compare your example 1 and example 2. So, example 1 does URL: "/update/upic1", POST: {"value":"foo"}, and example 2 does URL:" /update", POST: {"item": "upic1", "value":"foo"} or some derivative of, right? Are you using a 3rd party controller? If so, follow its structure. If not, not really sure if one is better than the other, but consistency is definitely a good thing. Edited December 20, 2016 by NotionCommotion 1 Quote Link to comment https://forums.phpfreaks.com/topic/302789-what-is-more-practical/#findComment-1540613 Share on other sites More sharing options...
AzeS Posted December 20, 2016 Author Share Posted December 20, 2016 (edited) So, time pased, i did alot of code and this is the result that i've come up to:Any suggestions ? Before you say something... its not ready yet i know the exec is missing ^^ <?php class iop { private $Db; function __construct($DB_CON) { $this->Db = $DB_CON; } public function uloader ($OID,$FILE,$stmt) { switch ($stmt) { case 0: #HEAD $sql = $this->Db->prepare("SELECT aboutpic FROM prflout WHERE owner=:e"); $res = $sql->fetchall(); break; case 1: #VID $sql = $this->Db->prepare("SELECT vid FROM prflout WHERE owner=:e"); $res = $sql->fetchall(); break; case 2 #FOOT $sql = $this->Db->prepare("SELECT impress FROM prflout WHERE owner=:e"); $res = $sql->fetchall(); break; case 3 #TEXT $sql = $this->Db->prepare("UPDATE prflout SET Aboutme=:f WHERE owner=:e"); $sql->execute(array(':f' => $FILE, ':e' => $OID)); $fmsg = "changed succesfully."; return $fmsg; break; default: # code... break; } # Delete old files and rewrite in db for udate $dir = $sdir; $fname = $FILE['name']; $ftmp = $FILE['tmp_name']; $ftype = $FILE['type']; $fsize = $FILE['size']; $ferr = $FILE['error']; $fname = preg_replace("/[^A-Z0-9._-]/i", "_", $fname); $fname = date("Y.m.d H.i.s") . rand() . $fname; if (!$ftmp) { $fmsg = "Error: youve not choosen a file please do so in order t upload a file."; return $fmsg; exit(); } if ($ftype != 'video/mp4' || $ftype != 'image/png') { $fmsg = "only mp4 files are allowed where sorry for that. Please upload a mp4 video"; return $fmsg; } if ($ferr !== UPLOAD_ERR_OK) { $fmsg = "An error occurred"; return $fmsg; exit; } $i = 0; $parts = pathinfo($fname); while (file_exists($dir . $fname)) { $i++; $fname = $parts["filename"] . "-" . $i . "." . $parts["extension"]; } $success = move_uploaded_file($ftmp, $dir . $fname); if (!$success) { $fmsg = "upload failed"; return $fmsg; } $f_dir = $dir . $fname; chmod($f_dir, 0644); if !(is_null($res)) { unlink($res); } switch ($stmt) { case 0: #HEAD #Updatedb $sql = $this->Db->prepare("UPDATE prflout SET aboutpic=:e"); $sql->execute(array(':e' => $f_dir)); break; case 1: #VID $sql = $this->Db->prepare("UPDATE prflout SET vid=:e"); $sql->execute(array(':e' => $f_dir)); break; case 2 #FOOT $sql = $this->Db->prepare("UPDATE prflout SET impress=:e"); $sql->execute(array(':e' => $f_dir)); break; default: # code... break; } $fmsg = "upload complete"; return $fmsg; } } ?> Edited December 20, 2016 by AzeS Quote Link to comment https://forums.phpfreaks.com/topic/302789-what-is-more-practical/#findComment-1540617 Share on other sites More sharing options...
ginerjm Posted December 20, 2016 Share Posted December 20, 2016 A quick read thru of your code and I am wondering what happened. Your original question was about updating a user profile. This code is about uploading and saving(?) a file. What is the connection? And does one really need a class to upload a file? Quote Link to comment https://forums.phpfreaks.com/topic/302789-what-is-more-practical/#findComment-1540618 Share on other sites More sharing options...
AzeS Posted December 20, 2016 Author Share Posted December 20, 2016 A quick read thru of your code and I am wondering what happened. Your original question was about updating a user profile. This code is about uploading and saving(?) a file. What is the connection? And does one really need a class to upload a file? yea, i do my own forum, so its necesary, thats wy i asked in the first place, im just an native english speaker so sorry for my grammer.. i Thought because of the "upic" phrase i used in my exampels that it was clear... thats wy i asked in the firstplace anyway xD and i think a class is necassary because i want to give the user the opportunity to update several images at once ok not exactly at once (im working on that so tips are welcome) but fast and effecient with the click of a button Quote Link to comment https://forums.phpfreaks.com/topic/302789-what-is-more-practical/#findComment-1540619 Share on other sites More sharing options...
ginerjm Posted December 20, 2016 Share Posted December 20, 2016 I can see there is a definite communication problem here. I don't understand a thing you just said. Good luck with whatever you are trying to do. Quote Link to comment https://forums.phpfreaks.com/topic/302789-what-is-more-practical/#findComment-1540620 Share on other sites More sharing options...
AzeS Posted December 20, 2016 Author Share Posted December 20, 2016 (edited) Your original question was about updating a user profile. This code is about uploading and saving(?) a file. i thought that the phrase upic was understandeble.What is the connection?i dont undersatand your question here...Id like to give the user the oppertunity to design his profile with pics and vids...so before i started coding, i thought to myself why not ask experienced devops that might have done this before, so that i dont do the bible of code and just mess up with things u know And does one really need a class to upload a file?I guess so eventually, there are two images and one video, for each distrubution an method on the page seems ridicolos for me Edited December 20, 2016 by AzeS Quote Link to comment https://forums.phpfreaks.com/topic/302789-what-is-more-practical/#findComment-1540622 Share on other sites More sharing options...
Psycho Posted December 20, 2016 Share Posted December 20, 2016 AzeS, I think you need to start by understanding what the intended actions are for the user - then build accordingly. What I believe I understand from the prior posts is that users are going to be updating their profile and that the profile can apparently have multiple pictures. What is not clear is whether the number of pictures is dynamic or fixed. For example, if you allow a user to have an avatar, a logo and a signature image, that is a fixed number of images. But, if you allow the user to upload multiple avatars that they can then cycle though, that would be a dynamic number. How you let the user manage those could be very different. If you have very specific entities for images (1 avatar, 1 profile, etc), then the form for the user profile should just have a single file field for each image entity. You could then have a single class to process any form submissions for user profiles. In that class it would check each of those file fields and (if anything was passed) run through the code to upload the image. If the upload succeeds, then include the image reference at the end of the class when running a SINGLE update query for the user profile to include the input fields as well as the images. However, for images, if the user does not pass a file for any image you should keep the existing entry (if there is one). You should provide a separate process for removing images. If you are going to allow an arbitrary number of images, then you need to figure out the workflow from the user's perspective. Do you want to allow them to upload multiple images at one time or only one image at a time. This might be a scenario where you have a special area to manage images. I can't really say since I don't know what you are doing. 1 Quote Link to comment https://forums.phpfreaks.com/topic/302789-what-is-more-practical/#findComment-1540623 Share on other sites More sharing options...
AzeS Posted December 20, 2016 Author Share Posted December 20, 2016 If you are going to allow an arbitrary number of images, then you need to figure out the workflow from the user's perspective. Do you want to allow them to upload multiple images at one time or only one image at a time. This might be a scenario where you have a special area to manage images. I can't really say since I don't know what you are doing. thats wy i asked in the first place, i decided that it can be implement for me if i use the "for each picture one upload button" methodbut i also liked to do an all at once button...and thats wy i asked for advise;because i dont have even a clue on how to get around this. its mostly for practice. Quote Link to comment https://forums.phpfreaks.com/topic/302789-what-is-more-practical/#findComment-1540624 Share on other sites More sharing options...
Psycho Posted December 20, 2016 Share Posted December 20, 2016 But, your question was about the CODE. You first need to determine what the user experience will be, THEN determine how it should be coded. I don't know what the images are for, how often users would be expected to be adding/changing/removing them, how the users will "use" the images, etc. etc. So, I cannot provide any advise on what the user experience should be. Quote Link to comment https://forums.phpfreaks.com/topic/302789-what-is-more-practical/#findComment-1540625 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.