| PHP, MySQL General PHP questions. Or go to our PHPsuexec Forum >> |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread |
|
|
#1 (permalink) |
|
Registered User
Fresh Surpasser
Joined in Jul 2003
1 posts
Gave thanks: 0
Thanked 0 times
|
Hi Guys,
I am trying to figure out how to copy the file from the temp upload dir to a directory under my web root. I know the file is getting uploaded by using the code: if(is_uploaded_file($_FILES['IFile']['tmp_name'])) which works However I tried all of the following code to move the file from the temp dir to a directory under my site without any luck $SrcFileName = $_FILES['IFile']['tmp_name']; $RealFileName = $_FILES['IFile']['name']; 1st Try: copy($_FILES['IFile']['tmp_name'], " /home/unicorn/public_html/JobTrack/".$RealFileName); Error: Warning: copy(/home/unicorn/public_html/JobTrack/unicorn_JobTrack.sql): failed to open stream: No such file or directory in /home/unicorn/public_html/jobtrack/Documents.php on line 47 2nd Try: move_uploaded_file($_FILES['IFile']['tmp_name'], "/home/unicorn/public_html/jobtrack/".$RealFileName); Error: Warning: move_uploaded_file(/home/unicorn/public_html/jobtrack/unicorn_JobTrack.sql): failed to open stream: Permission denied in /home/unicorn/public_html/jobtrack/Documents.php on line 48 Warning: move_uploaded_file(): Unable to move '/tmp/phpiC1Rjr' to '/home/unicorn/public_html/jobtrack/unicorn_JobTrack.sql' in /home/unicorn/public_html/jobtrack/Documents.php on line 48 3rd Try: $Command = "cp ".(string)$_FILES['IFile']['tmp_name']." /home/unicorn/public_html/jobtrack/".$RealFileName; passthru($Command); No Visual Error, but the operation does not happen. Thanks Michael |
|
|
|
|
#2 (permalink) |
|
Registered User
Comfy Contributor
Joined in May 2003
Lives in Florida
118 posts
Gave thanks: 0
Thanked 0 times
|
Your first try is correct, althought there a several minor details wrong. First the space between " and / in (, " /home/...). Next you don't have a directory called JobTrack in your public_html folder or if you do then that space could of been the problem; and finally when/if you do have that directory make sure it has world write and execute permissions; just make it 777 or 757. Also unless you plan to use those variables elsewhere in the code its best just to do:
copy ($_FILES['IFile']['tmp_name'], "/home/unicorn/public_html/JobTrack/".$_FILES['IFile']['name']) or die ("Error copying file."); Using relative path works too, if your uploading script or whatever you're doing is in your public_html directory then you can use this code: copy ($_FILES['IFile']['tmp_name'], "./JobTrack/".$_FILES['IFile']['name']) or die ("Error copying file."); or copy ($_FILES['IFile']['tmp_name'], "JobTrack/".$_FILES['IFile']['name']) or die ("Error copying file."); And if your script is simply in the same directory as where you want to move the file then you can do: copy ($_FILES['IFile']['tmp_name'], "./".$_FILES['IFile']['name']) or die ("Error copying file."); or copy ($_FILES['IFile']['tmp_name'], $_FILES['IFile']['name']) or die ("Error copying file.");
__________________
Profession: Programmer, Gamer, Web Developer Website: http://www.reanimated.net/ - Server: Quela |
|
|