PHP Upload Directory Help

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
Method
Forum Newbie
Posts: 11
Joined: Tue Aug 26, 2003 5:50 am

PHP Upload Directory Help

Post by Method »

I have currently been working with a php upload script that works, but uploads to the same directory as the file... I have been searching for a way to upload to a specific directory ie. /uploads/ but can't seem to get it working.. here is my code that i have so far... (mind you this is only the php file):

Code: Select all

<? 
if ($HTTP_POST_VARS['submit'])  
{ 
	$source = $_FILES['file']['tmp_name'];
	$sourceend = $_FILES['file']['name'];
	$path = "uploads/";

    if (!is_uploaded_file($source))  
    { 
    $error = "You did not upload a file!"; 
    @unlink($source); 
    print "You did not enter a file to upload.";
    } 
    else  
    { 
    $maxfilesize=300000; 
        if ($source > $maxfilesize) 
        { 
            $error = "File is too large."; 
            @unlink($source); 
        } 
        else  
        { 
        	 @chmod($path, 01777);
             @copy($source, $path . $sourceend);
             @unlink($source);
    	     @chmod($path, 01744);
        } 
        

         print "File has been successfully uploaded!<br><a href="index.html">Click here to Return</a>"; 
             exit;   
 
            }  
      } 

?>
Any help would be GREATLY appreciated!
Last edited by Method on Tue Aug 26, 2003 10:28 pm, edited 1 time in total.
User avatar
xisle
Forum Contributor
Posts: 249
Joined: Wed Jun 25, 2003 1:53 pm

Post by xisle »

Is the $path set to your destination directory? It looks ok otherwise.
Method
Forum Newbie
Posts: 11
Joined: Tue Aug 26, 2003 5:50 am

Post by Method »

yes it is set to that directory...
Method
Forum Newbie
Posts: 11
Joined: Tue Aug 26, 2003 5:50 am

Post by Method »

blah... i found the error...

i just needed to set the $path = "uploads/"; to $path = "uploads//";

it works fine now...
Post Reply