[PHP] When using mkdir(), what is the parent directory of the newly created folder?

While it doesn't help, I would advice against building an app from scratch all by yourself if you don't have much experience.

I don't know your code, but I could imagine a bunch of security holes to be exploited already. For example a user could upload a different file than an image (file endings aren't sufficient to find out about the type), they could then inject code via a form field that gets executed, which than executes the uploaded file which than compromises the server. If there's any damage done to the server, you would probably be the one who'd be held responsible, fiscally that means. I guess there's at least one nerd at your school who's able to exploit such holes. So you either be confident that your app is secure (which would require you to learn a great many things), or do not productively use/publish your software. As a compromise you should at least use a framework. Those are abstracting away most problems, are well-documented and just require you to use them correctly (as described in the docs).

In any circumstance you should ask the admin whether he could create a partition with the nodev, nosuid and noexec (most important) flags and mount it to the directory where you want to store the files. If this is not an option, consider storing the pictures in an SQL database as blobs. Also the PHP configuration shouldn't allow command/shell execution, symlinking etc. and of course, you should validate form input.

Now to your actual problem: Have a look at the pwd() function. It returns your currently working directory. That means that any paths (except absolute paths starting with a /) are actually located relative to this directory. You might also want to use the global constant DIRECTORY__SEPERATOR instead of a '/' character, although the PHP runtime automatically takes care to convert the '/' into a '\' under Windows.

It doesn't actually matter where you store the pictures, but Webservers like Apache or nginx don't serve files outside of the defined webroot (publichtml) by themself. But you could implement a mechanism to serve a file or its contents within your PHP app, although this is not just easy peezy (learn about HTTP headers). This would be required if you store them within a database. Also, you might want to learn about rewrite rules. A good practice is to rewrite any request to any file/path to the index.php, and let the index.php handle them all, _except for existing static files in defined directories (for example the directory and its subdirectories containing your pictures). That way you don't have to worry what you pack into the public_html directory, you can put all into it. Just don't put anything but the said static files in your directories with static files.

/r/learnprogramming Thread