![]() |
|
[PHP] Trying to get a file to upload to the correct directory. - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Web Development (https://hackforums.net/forumdisplay.php?fid=183) +---- Thread: [PHP] Trying to get a file to upload to the correct directory. (/showthread.php?tid=5934146) |
Trying to get a file to upload to the correct directory. - Babadook - Jan 26, 2019 Edit: Edited original post with a new issue. x2 Edit x3 Thank you everyone. I got everything working! RE: Trying to get a file to upload to the correct directory. - TCP - Jan 26, 2019 Is $target_file_p the one being used for the upload of the image as in the script? It looks like "../uploads/Photos" is missing a / before the filename PHP Code RE: Trying to get a file to upload to the correct directory. - Babadook - Jan 26, 2019 (Jan 26, 2019 07:42 AM)Exp500 Wrote: Is $target_file_p the one being used for the upload of the image as in the script? It looks like "../uploads/Photos" is missing a / before the filename Thank you so much. I knew it'd be something simple like that. RE: Trying to get a file to upload to the correct directory. - Disease - Jan 26, 2019 (Jan 26, 2019 08:50 AM)Babadook Wrote: Thank you so much. I knew it'd be something simple like that. A helpful debugging technique, when running down issues like this, is to watch the values of important variables. In this case, you knew the upload was working. It just wasn't being moved to the correct directory. You could've checked the value of the $target_file_p variable. Either by printing it out via print()/echo() or by inspecting it via print_r()/var_dump(). RE: Trying to get a file to upload to the correct directory. - newQuery - Jan 26, 2019 Define a constant to your ROOT's path directory and use it for creating a link to the upload path. RE: Trouble getting file extension on file uploads to use in sorting files - Babadook - Feb 1, 2019 I've updated with a new issue. Thank you everyone for the help on the previous error I had. RE: File sorting system, assigning a wrong variable. - +Haze - Feb 1, 2019 (Jan 26, 2019 07:16 AM)Babadook Wrote: Edit: Edited original post with a new issue. x2 Just a heads up buddy, it's deemed bad programming practice to use goto statements in your code. It creates spaghetti code that becomes increasingly difficult to read and maintain. Also, Code ($fileType == "mp4" || $fileType == "ogg" || $fileType == "wmv" || $fileType == "avi" || $fileType == "webm" || $fileType == "mov")is a bit messy, try something like. Code function isExtensionValid($fileType, $validExtensions) {That way you can just do Code if (isExtensionValid($fileType, ["mp4", "ogg" , "wmv" , "avi" , "webm" , "mov"]) {I wrote this on top of my head so it may not fully work, but this approach makes it easier to maintain and read your code. RE: File sorting system, assigning a wrong variable. - Abruptum - Feb 1, 2019 (Feb 1, 2019 11:41 AM)+Haze Wrote: Just a heads up buddy, it's deemed bad programming practice to use goto statements in your code. It creates spaghetti code that becomes increasingly difficult to read and maintain. A even better solution would be to use in_array() PHP Code And pleas never never never never never EVER use goto..... The results can only be garbage. Do it like this : PHP Code RE: File sorting system, assigning a wrong variable. - +Haze - Feb 1, 2019 (Feb 1, 2019 04:00 PM)Abruptum Wrote: x I'm not all that familiar with PHP as I used to but yeah that's a better cleaner solution. RE: File sorting system, assigning a wrong variable. - Babadook - Feb 1, 2019 Thank all of you for your help. I'll start testing your suggestions. If it's not obvious by now, I'm teaching myself as I go. The goto statements, I know that nobody likes them, but without them, my code ran through all of my if statements whether they were true or false so I needed something to skip the codes it didn't need. Hopefully I can get everything working without them. Thank you again! RE: File sorting system, assigning a wrong variable. - Jоey - Feb 1, 2019 (Feb 1, 2019 07:23 PM)Babadook Wrote: Thank all of you for your help. I'll start testing your suggestions. If it's not obvious by now, I'm teaching myself as I go. The goto statements, I know that nobody likes them, but without them, my code ran through all of my if statements whether they were true or false so I needed something to skip the codes it didn't need. Hopefully I can get everything working without them. Thank you again! When you're utilizing if with else-if's, the first conditional that is met true the rest of the else-if/else's are skipped over. RE: File sorting system, assigning a wrong variable. - Babadook - Feb 1, 2019 Down to my last error, everything to this point has been fixed. Just need to figure out where I'm messing up the file_exists part. |