icon Get the most out of Surmunity, read our tips here! Need an interesting blog to read? You've got to read the Surpass Blog! | Welcome! Please register to access all of our features.

» Surpass Web Hosting Forums » Discussions » PHP, MySQL » File Uploads & Moving em Around

PHP, MySQL General PHP questions. Or go to our PHPsuexec Forum >>

Closed Thread
 
LinkBack Thread Tools Search this Thread Rate Thread
Old July 11th, 2003, 1:41 AM   #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
unicorn is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Old July 12th, 2003, 1:28 PM   #2 (permalink)
Registered User
Comfy Contributor
 
OmicroN's Avatar
 
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
OmicroN is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On