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
https://forums.phpfreaks.com/topic/177864-solved-move_uploaded_file/
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"]}");

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

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

 

Archived

This topic is now archived and is closed to further replies.

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