copy() or move_uploaded_file

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
eliddell
Forum Newbie
Posts: 8
Joined: Thu Apr 22, 2010 12:31 pm

copy() or move_uploaded_file

Post by eliddell »

hi all,
i am creating a php script that will allow my user to upload an image from there computer to a folder on my website..
problem is that i am using godaddy shared hosting and the temp folder they use for php uploads is outside my sites root and thus gives me permission problems when i try to copy or move the temp file to a given directory..

the line of code that spits out the error is - $copy = copy($_FILES['imagefile']['tmp_name'], "$idir" . $_FILES['imagefile']['name']); // Move Image From Temporary Location To Permanent Location

i get a permissions problem as stated and godaddy said that i can not change the permissions on the said temp folder that i am copying from.. they did say that perhaps i can use a different command.. i tried move_uploaded_file but still get the same error.. does anyone have ANY advise..

erik
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: copy() or move_uploaded_file

Post by Christopher »

eliddell wrote:i get a permissions problem as stated and godaddy said that i can not change the permissions on the said temp folder that i am copying from.. they did say that perhaps i can use a different command.. i tried move_uploaded_file but still get the same error.. does anyone have ANY advise.
First, you don't need to change permissions on the tmp folder, you need to change permissions on to directory to which you are copying the files. Second, you should use move_uploaded_file() for uploads.
(#10850)
eliddell
Forum Newbie
Posts: 8
Joined: Thu Apr 22, 2010 12:31 pm

Re: copy() or move_uploaded_file

Post by eliddell »

trust me when i say, that the permissions on the folder i am moving it TO is set to 777 i tried using move_uploaded_file and still get an error..

that error
Warning: move_uploaded_file(/vegancookie.jpg) [function.move-uploaded-file]: failed to open stream: Permission denied in D:\Hosting\5343850\html\admin\editGal.php on line 97

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'D:\Temp\php\phpF850.tmp' to '/vegancookie.jpg' in D:\Hosting\5343850\html\admin\editGal.php on line 97
ERROR: Unable to upload image.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: copy() or move_uploaded_file

Post by John Cartwright »

Unable to move 'D:\Temp\php\phpF850.tmp' to '/vegancookie.jpg'
Hint: Take a look at the file path you are trying to move the to.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: copy() or move_uploaded_file

Post by Christopher »

:roll:
(#10850)
Post Reply