I am not a formally trained programmer.

I am having problems with the move_uploaded_file function.

I can upload a file and use the move_uploaded_file to save it to the same directory that my form page was called from.

How can I change the path so that it saves the uploaded file in a subdirectory named "profile_imgs" instead of the current directory?

Here is an example using an upload 'mbr_image' file which I want to save as "test.jpg"

$mbr_img_name="test.jpg";
if (move_uploaded_file($_FILES['mbr_image'] ['tmp_name'] ,$mbr_img_name))
			{
			print "Received {$_FILES['mbr_image']['name']} -
				it's size is: {$_FILES['mbr_image']['size']}";
			}
			else
			{
				print "Upload failed!";
			}	

The above saves the temporary upload to a file named test.jpg but it saves it in the current directory of the page that calls it. I want to save it in a subdirectory one level under the current page's directory.

How do I modify my $mbr_img_name variable to include the folder path name where I want to save this?

I tried setting $mbr_img_name="/profile_imgs/test.jpg"

But if I do that I get error messages from the error handler:

Encountered error: 2 in /home/omgma/public_html/member_community/profile/profile_updt_form.php, line 54: move_uploaded_file(/profile_imgs/Conjurer.png) [function.move-uploaded-file]: failed to open stream: No such file or directory

Encountered error: 2 in /home/omgma/public_html/member_community/profile/profile_updt_form.php, line 54: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpAj6xhQ' to '/profile_imgs/Conjurer.png'

    You've shown us your code, but how about a description of what's going wrong and any related error messages?

    One problem I see is here:

    $mbr_imgs_path = '/profile_imgs/' ;

    The path that is need is on the filesystem, and that path above says that there is a folder called 'profile_imgs' on the root of the server's hard drive. I doubt that is correct - you'll probably want to specify a path either relative to the current script or use a proper absolute path (e.g. '/home/yoursite/path/to/folder') - see $_SERVER['DOCUMENT_ROOT'] for help with that.

    EDIT: Also, when posting PHP code, please use the board's [noparse]

    ..

    [/noparse] bbcode tags (not the generic [noparse]

    [/noparse] ones) as they make your code much easier to read/analyze.

      Original was messy, I hit the post button when I thought I was peviewing. :eek:

        Path name was it. Thanks!

        $mbr_img_name="/home/omgma/public_html/member_community/profile/profile_imgs/test.jpg";
          Write a Reply...