Jump to content

AnxiousInSeattle

New Members
  • Posts

    4
  • Joined

  • Last visited

AnxiousInSeattle's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thank you so much for your help!! It worked, but I'm new here (probably painfully obvious) and I'm not sure which answer I should mark as the solution... ginerjm for suggesting the right answer even though I didn't understand it or requinix for being able to explain giner's answer. Please let me know!
  2. @ginerjm Uhh, I'm not quite sure that my MyProject (singular, not plural by the way) folder is under the "true html root folder," because I'm not sure what that means. For context anyway, I run Manjaro Linux (apparently based on Arch Linux), and since I'm using a lot of php, I had to download xampp and all my files have to be based out of its folder. So basically, the file I'm in right now (named addimg.php) is at location: /opt/lampp/htdocs/MyProject/scripts/addimg.php where / is the home folder. Like, when I go to just "/" on my file explorer, it just says that it's my internal hard drive. The fact that I run Linux also means I can't use backslashes (\). Always has to be forward slashes. Anyway, I will have to host this on an external server later, so I can't depend on the files on my computer not related to my project. Everytime I refer to another file, I always have to move within the MyProject folder. That is, I can't use the actual file location of /op/lampp... because it would just break my code when I run it on the server. Hoping that was fine, I did the following: $_SERVER['DOCUMENT_ROOT'] = '/MyProject'; fileDestination = $_SERVER['DOCUMENT_ROOT']."/uploads/".$fileNameNew; move_uploaded_file($fileTmpName, $fileDestination); (I also tried $_SERVER['DOCUMENT_ROOT'] . '/MyProject'; by the way) The "/uploads/" part turns red for some reason, but I don't get an error and it runs. But, even though it runs without error, it doesn't work. My uploads folder is still empty I hope that maybe my more in-depth explanation of my device and project file structure gives you any other context that you may have been missing, and you'd be able to help me out. This is my third day of being stuck on this problem, and I have no one around me to turn to for help. Please let me know if you have any other suggestions. If you don't, please inform me of that as well. I'd rather know if I should just give up, than continuously refresh this page hoping for a reply... Thanks.
  3. @ginerjm When I say root, I'm referring to the folder that all my project files are in. So in: - MyProject - pages - scripts - function.php - style - uploads the "root" is MyProject. I am aware of what the dots mean. The uploads folder is on the same level as the scripts folder, so if I’m in function.php, one dot to leave the file itself which puts me in the scripts folder, then one more dot to leave the scripts folder, then a slash to go into the uploads folder. It works for other functions like in the header() function to load another page, but not in the move_uploaded_file() function for some reason. I don't understand what you mean by the $_SERVER stuff. Please elaborate.
  4. I’ve got the basics of how file uploads in PHP work. Once the submit button has been clicked, I grab the important stuff like the file size and file extension and check to make sure the user isn’t uploading anything too big or weird. After that, you give the file a new name, then move it into a folder called “uploads” located in your root folder. All resources I’ve found online say to use the move_uploaded_file() command to move the uploaded file from its temporary location ($_FILES['file']['tmp_name']) to that uploads folder. The problem is, all those resources give examples of rather small projects with all files located right in the root folder. In my case, the scripting file is not located directly in the root folder but within a folder called scripts in the root folder. - MyProject - pages - scripts - function.php - style - uploads I’ve tried calling that move_uploaded_file() function with the destination as "uploads/ and as "../uploads/" (with the two dots in front) but neither work. //Getting file and its name $file = $_FILES["projImg"]; $fileName = $_FILES["projImg"]["name"]; //Getting temporary location of file and file extension (ie jpg, png, etc) $fileTmpName = $_FILES["projImg"]["tmp_name"]; $fileNameSplit = explode('.', $fileName); $fileExt = strtolower(end($fileNameSplit)); //Giving file new name based on time created $fileNameNew = uniqid('', true).".".$fileExt; //Setting file new destination $fileDestination = "../uploads/".$fileNameNew; //Trying to move file from temporary location to new destination, NOT WORKING :( move_uploaded_file($fileTmpName, $fileDestination); I think the problem is honestly that I can’t have dots within that move_uploaded_file() function. Whenever I echo $fileDestination, it gives me ../uploads/616deb42769007.77898958.jpg, instead of MyProject/uploads/616deb42769007.77898958.jpg. The dots aren’t working within the function, so there must be some rule as to how to put relative file locations within that particular function. But I can’t find such a rule, which is why I’ve turned to this site after three days now of being stuck. Is there something special I have to do to get the right relative location of the uploads folder?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.