Jump to content

[SOLVED] move_uploaded_file


mechedd

Recommended Posts

Hi again,

 

Last post for tonight! I promise!

 

Ok, so I now have the $_FILES array working fine... I can call on the file name and type and tmp_name.

 

Now  I am trying to move the file to a directory on the server (I am hosted by GoDaddy), but I cannot figure out how to write the directory so that it works. 

 

GoDaddy gives me an "Absolute Hosting Path", which is something along the lines of D:\Hosting\123456\....  The temporary directory (which I find by calling the $_FILES array) is something similar, but more like D:\Temp\....

 

So I have a folder called Upload and I want to move the temp file to this folder.  I tried doing:

 

move_uploaded_file($_FILES["File1"]["tmp_name"],
"D:\Hosting\123456\html\upload\" . "\" . $_FILES["File1"]["name"]);

 

But it doesnt like the \ and I get an error.

 

Plus, the directories on my website use forward slashes.... what do i have to do?  Do I have all of the information I need?  Do I use the Absolute Hosting Path?

Link to comment
Share on other sites

You need to remove that additional \. Say you uploaded a file named "hello.jpg", the string created would be:

 

D:\Hosting\123456\html\upload\\hello.jpg

 

You want:

 

D:\Hosting\123456\html\upload\hello.jpg

 

so:

move_uploaded_file($_FILES["File1"]["tmp_name"],
"D:\Hosting\123456\html\upload\{$_FILES["File1"]["name"]}");

Link to comment
Share on other sites

I just tried that and I get this:

 

Warning: move_uploaded_file(D:\HostingE3020\html\uploaddbf09front.JPG) [function.move-uploaded-file]: failed to open stream: No such file or directory in D:\Hosting\123456\html\phptest.php on line 24

 

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'D:\Temp\php\phpE0E5.tmp' to 'D:\HostingE3020\html\uploaddbf09front.JPG' in D:\Hosting\123456\html\phptest.php on line 24

 

I can see two errors here.  The first is that the file and directory do not have a \ between them when I leave it out. (uploaddbf09front.JPG)

 

 

Second, the Absolute Hosting Path was switched somehow... It is supposed to be D:\Hosting\123456\html\..... and ad you can see it got switched to D:\HostingE3020\html\....

 

I dont know what is going on I have the path right in my script.

 

Any Ideas?

 

-mechedd

Link to comment
Share on other sites

When I try that I get:

 

Warning: move_uploaded_file(D:\Hosting\123456\html\upload\dbf09side.JPG) [function.move-uploaded-file]: failed to open stream: Permission denied in D:\Hosting\123456\html\phptest.php on line 24

 

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'D:\Temp\php\php4194.tmp' to 'D:\Hosting\123456\html\upload\dbf09side.JPG' in D:\Hosting\123456\html\phptest.php on line 24

 

Permission is denied...  The good thing is the file path now appears how it should.  Is this something I have to call GoDaddy about or is there some way to grant permission?

 

-mechedd

 

Link to comment
Share on other sites

I got it to work.  With GoDaddy you have to create a directory in the IIS Manager and wait half a day for them to set it up for you if you want to be able to give the directory web writable permissions. 

 

Thanks for all of your help!

 

-mechedd

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.