A community in which webmasters can ask for help with topics such as PHP coding , MySQL , IT jobs, web design, IT security.
Current location:homephp forumphp talk in 2009 yearPHP: Saving files with PHP to different root directory? - page 1
User InfoPosts
PHP: Saving files with PHP to different root directory?#1
OK when I save uploaded files with PHP via move_uploaded_file() I cannot use an absolute URL I have to use a relative one. My site has 2 root directories one for the http side and one for the https side: httpdocs and httpsdocs respectively. So if my script is on the https side how can I save the file to a location on the http side?

Thanks!

UPDATE
OK so it seems like I am using the wrong absolute path convention I am doing it like this:

$dir = (https://www.mydomain.com/masonic_images/(;
move_uploaded_file($_FILES[(blue_image(][(tmp_name(], $dir.$new_name);

posted date: 2009-04-14 11:02:00


Re: PHP: Saving files with PHP to different root directory?#2
I had made out the solution of this problem. click to view my topic...

hope that hepls.

posted date: 2009-04-14 11:02:01


Re: PHP: Saving files with PHP to different root directory?#3
Why can't you use an absolute path?

posted date: 2009-04-14 11:05:00


Re: PHP: Saving files with PHP to different root directory?#4
If you cannot use the absolute path because you don(t know what the absolute path is, use PHP(s realpath() to figure out what it is and then use it.

posted date: 2009-04-14 11:09:00


Re: PHP: Saving files with PHP to different root directory?#5
@Chad I get an error when I use an absolute path. "Warning: move_uploaded_file(): URL file-access is disabled in the server configuration." Is that something I can adjust in an .htaccess file?

posted date: 2009-04-14 11:10:00


Re: PHP: Saving files with PHP to different root directory?#6
Can you show the move_uploaded_file call? It sounds like you're putting a URL instead of a file path, that won't work.

posted date: 2009-04-14 11:11:00


Re: PHP: Saving files with PHP to different root directory?#7
move_uploaded_file() doesn(t accept URLs for either parameter. The destination is an absolute path on your filesystem.<?php$dir = (/var/www/httpsdocs/(; // Adjust to your configurationmove_uploaded_file($_FILES[(blue_image(][(tmp_name(], $dir.$new_name);As @apphacker suggested. you can use realpath(__FILE__) to determine the absolute path to a file.

posted date: 2009-04-14 11:12:00


Re: PHP: Saving files with PHP to different root directory?#8
Thanks, I tried what you said and I got this error: "Warning: move_uploaded_file(): open_basedir restriction in effect. File(../../httpdocs/masonic_images/41_red_391-1-l.jpg) is not within the allowed path(s)"

posted date: 2009-04-14 11:15:00


Re: PHP: Saving files with PHP to different root directory?#9
@Chad I added the call above.

posted date: 2009-04-14 11:21:00


Re: PHP: Saving files with PHP to different root directory?#10
So how do I write the absolute path correctly?

posted date: 2009-04-14 11:22:00


Re: PHP: Saving files with PHP to different root directory?#11
Your web server has PHP configured to block all file accesses outside the current site root. Unless you can turn the open_basedir restriction off, there is no way to place the images in the other directory.

posted date: 2009-04-14 11:26:00


Re: PHP: Saving files with PHP to different root directory?#12
@Jon is there a way to do that with .htaccess? Thanks

posted date: 2009-04-14 11:33:00


select page: « 1 2 »
Copyright ©2008-2017 www.momige.com, all rights reserved.