Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 15 of 15
  1. #1
    New Coder
    Join Date
    Sep 2003
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    File Upload to FTP +options

    hello everyone. i'm trying to find some sort of code or script that lets me do the following.

    on my website, i need an FTP drop box type thing. viewers can browse their computer for a file they want to upload. then from either a radio button or drop down menu, choose one of two directories to upload it to. and depending on which directory they choose, i need an e-mail notification to go to an e-mail address designated for that directory.

    so for example, say someone wants to upload test.pdf from their computer. they browse for it, choose it, then choose the directory it uploads to. if they choose a directory called "color", then it would e-mail john@hotmail.com letting him know a file was uploaded... but if they chose a directory called "black and white" it would e-mail kim@hotmail.com letting them know a file was uploaded. then the user would be taken back to the websites index page, or a page sayign the file has been uploaded or something.

    does anyone know of a script, or where to find one that can do this? i looked around on many many sites for a couple hours but couldn't really find anything.

    any help would be extremly appreciated. thank you.

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    In what language does it need to be in? Have you checked out www.hotscripts.com ?
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #3
    New Coder
    Join Date
    Sep 2003
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts
    any language is fine... php, cgi, perl, java, html. as long as it works, it would be great. i tried looking there. i was actually on that site alone for about an hour and a half going through all the results. but almost everything that i seemed to come accross was for an interactive personal database thing, where you upload a file for your own use and it lists what you have uploaded.

  • #4
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Okay I made one for you in php. There is a file called uploader.php this is the page the user makes the upload from. The page has php that checks for null values for both the file upload field and the select menu (directory chooser). It will spit out errors if either one is null. If none are null then proceed to upload the file. Once uploaded it will redirect the user back to the index.php page outputting that they uploaded a file to so and so directory. An email is also sent to the person of your choice dependent upon the directory that was chosen. I commented the files pretty well so you should be able to find your way around. I strongly advise that you give the upload option to a user based on a members only option. Having this open to the public is just asking for trouble. The email sent contains the file name, upload directory, and ip address of the user.

    uploader.php
    PHP Code:
    <?php
    $error 
    ""// Set a variable that will be used for errors
    $sendTo ""// Set a variable that will be used for emailing
    if(isset($_POST['upload']) && $_POST['upload'] == 'Upload File'// Form is submitted
    {
        
    $whereto $_POST['where']; // Gets post value from select menu
        
    $whatfile $_FILES['uploadedfile']['name']; // Gets file value from file upload input
        
    $subject "File uploaded to "$whereto ." directory"// This is the subject that will appear in the email
        
    $from "Upload form <noreply@yourdomain.com>";
        if(empty(
    $whereto)) // Checks to see if $whereto is empty, if so echo error
        
    {
            
    $error "You need to choose a directory.<br />";
        }
        if(
    $whatfile == NULL// Checks to see if file input field is empty, if so throw an error
        
    {
            
    $error .= "You need to choose a file.";
        }
        if(!empty(
    $whereto) && $whatfile != NULL//if no errors so far then continue uploading
        
    {
            
    $target_path "$whereto/"// The directory the file will be placed
            
            /* Add the original filename to our target path. Result is "uploads/filename.extension" */
            
    $target_path $target_path basename($whatfile);
            if(
    move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path))
            {
                
    header("Location: index.php?to=$whereto"); // Directs user back to page of choice
            
    }
            else
            {
                
    /* if there was a problem then throw an error */
                
    $error .= "There was an error uploading the file, please try again!";
            }
            if(empty(
    $error))
            {
                if(
    $whereto == "uploads1"// Change $sentTo depending on the directory chosen
                
    {
                    
    $sendTo "Jim <jim@yourdomain.com>"// Change this to an email address of your own
                
    }
                if(
    $whereto == "uploads2")
                {
                    
    $sendTo "Kim <kim@yourdomain.com>"// Change this to an email address of your own
                
    }
                
    /* The below will be what is shown in the email */
                
    $body "You have received the following from the web based upload form:\r\n";
                
    $body .= "---------------------------------------------------------------\r\n";
                
    $body .= "Subject:    File uploaded to "$whereto ." directory\r\n";
                
    $body .= "File name:  "$whatfile ."\r\n";
                
    $body .= "Upload directory: "$whereto ."\r\n";
                
    $body .= "Uploader's IP address: "$_SERVER['REMOTE_ADDR'] ."\r\n";
                
    $body .= "---------------------------------------------------------------\r\n";
              
                  
    /* headers used to show from field in email client */
                
    $headers 'From: '.$from."\r\n" .
                    
    'Reply-To: '.$from
                
                
    /* this actually sends the mail */
                
    mail($sendTo$subject$body$headers);
            }
        }
    }
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>File Upload</title>
    </head>

    <body>
    <div>
    <?php
    if(!empty($error))
    {
    echo 
    $error;
    }
    ?>
    </div>
    <form enctype="multipart/form-data" action="<?php echo $_SERVER['SCRIPT_NAME']?>" method="POST">
        <input type="hidden" name="MAX_FILE_SIZE" value="100000" />
        Choose a file to upload: <input name="uploadedfile" type="file" /><br />
        <select name="where">
            <option value="">Choose a directory</option>
            <option value="uploads1">uploads1</option>
            <option value="uploads2">uploads2</option>
        </select>
        <input type="submit" name="upload" value="Upload File" />
    </form>
    </body>
    </html>
    index.php
    PHP Code:
    <?php
    $directory 
    $_GET['to']; // This checks the url getting the value for the to=
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Index Page</title>
    </head>

    <body>
    <?php
    if(!empty($directory)) // if to=something then echo that the file was uploaded in so and so directory
    {
        echo 
    "Your file has been uploaded to the "$directory ." directory.";
    }
    ?>
    </body>
    </html>
    YOU MUST CHMOD THE DIRECTORIES TO 777 FOR THIS TO WORK PROPERLY!
    Attached Files Attached Files
    Last edited by _Aerospace_Eng_; 04-28-2006 at 12:37 AM.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #5
    New Coder
    Join Date
    Sep 2003
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thank you so much for the help. i'm trying to get this all worked out but i think i'm having problems. when i tried to test it out, i got this error:

    Warning: move_uploaded_file(): Moved: '/var/tmp/php4WkS4p' to 'irvine/New Text Document.txt' in /home/variable/public_html/upload/uploader.php on line 24

    Warning: Cannot modify header information - headers already sent by (output started at /home/variable/public_html/upload/uploader.php:24) in /home/variable/public_html/upload/uploader.php on line 26


    it's more then likely somethign completly obvious that i'm missing and not noticing. any ideas?

  • #6
    New Coder
    Join Date
    Sep 2003
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts
    and i'm so sorry i forgot to ask this at the begining. but how would i go about adding in 2 text fields for someone to type in their name and a company name?

  • #7
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    The error is being returned because you didn't chmod your folders to 777 this is easiest done through your FTP program. Hold on now. You are wanting this to be public? That is the LAST thing you want to do. I take no responsibility for what might happen to your site of some ignorant user uploads something you don't want on your server. I told you this needs to be in a protected area. You obviously didn't read it to carefully or you would know about that and that you needed to chmod your folders to 777.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #8
    New Coder
    Join Date
    Sep 2003
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts
    but they are chmod to 777. i changed all folders and subfolders to 777. and this whole thing is going to be in a password protected directory once i get everything right so only someone with authorized access will be aloud to get to the page.

    Last edited by fallingintoZero; 05-01-2006 at 10:43 PM.

  • #9
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Chmod each one individually just to be sure. If you can use chmod through your file manager on your server then do it that way as well. Sometimes chmodding through FTP doesn't work properly. What type of files will be uploaded?
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #10
    New Coder
    Join Date
    Sep 2003
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts
    mostly pdf's, quarkxpress files, photoshop images, and rarely stuff it and zip files.

  • #11
    New Coder
    Join Date
    Sep 2003
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts
    checked chmod's through the manager and they are all at 777 as well. i set the php files to 777 also because 644 wasn't working and it still didn't help. i can't figure it out

  • #12
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    I don't know what to tell you sorry. I tested the script before I gave it to you. It worked fine on my server.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #13
    New Coder
    Join Date
    Sep 2003
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts
    alright. well thank you very much for your help. providing me with what you have was completly awesome as it is. i'm going to paste the code from the file i'm using because maybe i forgot to change some info or something.

    PHP Code:
    <?php
    $error 
    ""// Set a variable that will be used for errors
    $sendTo ""// Set a variable that will be used for emailing
    if(isset($_POST['upload']) && $_POST['upload'] == 'Upload File'// Form is submitted
    {
        
    $whereto $_POST['where']; // Gets post value from select menu
        
    $whatfile $_FILES['uploadedfile']['name']; // Gets file value from file upload input
        
    $subject "File uploaded to "$whereto ." directory"// This is the subject that will appear in the email
        
    $from "FTP UPLOAD <vipirv@hotmail.com>";
        if(empty(
    $whereto)) // Checks to see if $whereto is empty, if so echo error
        
    {
            
    $error "You need to choose a directory.<br />";
        }
        if(
    $whatfile == NULL// Checks to see if file input field is empty, if so throw an error
        
    {
            
    $error .= "You need to choose a file.";
        }
        if(!empty(
    $whereto) && $whatfile != NULL//if no errors so far then continue uploading
        
    {
            
    $target_path "$whereto/"// The directory the file will be placed
            
            /* Add the original filename to our target path. Result is "uploads/filename.extension" */
            
    $target_path $target_path basename($whatfile);
            if(
    move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path))
            {
                
    header("Location: index.php?to=$whereto"); // Directs user back to page of choice
            
    }
            else
            {
                
    /* if there was a problem then throw an error */
                
    $error .= "There was an error uploading the file, please try again!";
            }
            if(empty(
    $error))
            {
                if(
    $whereto == "uploaded/irvine/incoming"// Change $sentTo depending on the directory chosen
                
    {
                    
    $sendTo "Irvine <vipirv@hotmail.com>"// Change this to an email address of your own
                
    }
                if(
    $whereto == "uploaded/sandiego/incoming")
                {
                    
    $sendTo "San Diego <vipsd@hotmail.com>"// Change this to an email address of your own
                
    }
                
    /* The below will be what is shown in the email */
                
    $body "You have received the following from the web based upload form:\r\n";
                
    $body .= "---------------------------------------------------------------\r\n";
                
    $body .= "Subject:    File uploaded to "$whereto ." directory\r\n";
                
    $body .= "File name:  "$whatfile ."\r\n";
                
    $body .= "Upload directory: "$whereto ."\r\n";
                
    $body .= "Uploader's IP address: "$_SERVER['REMOTE_ADDR'] ."\r\n";
                
    $body .= "Company: ".$company ."\r\n";
                
    $body .= "Contact: ".$contact ."\r\n";
                
    $body .= "PO Number: ".$ponumber ."\r\n";
                
    $body .= "---------------------------------------------------------------\r\n";
              
                  
    /* headers used to show from field in email client */
                
    $headers 'From: '.$from."\r\n" .
                    
    'Reply-To: '.$from
                
                
    /* this actually sends the mail */
                
    mail($sendTo$subject$body$headers);
            }
        }
    }
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml"><HEAD><TITLE>VIP</TITLE>

    <BODY>
    <div>
    <?php
    if(!empty($error))
    {
    echo 
    $error;
    }
    ?>
    </div>
    <form enctype="multipart/form-data" action="<?php echo $_SERVER['SCRIPT_NAME']?>" method="POST">
        <input type="hidden" name="MAX_FILE_SIZE" value="100000" />
        Choose a file to upload: <input name="uploadedfile" type="file" /><br />
        <select name="where">
            <option value="">Choose a directory</option>
            <option value="uploaded/irvine/incoming">Irvine</option>
            <option value="uploaded/sandiego/incoming">San Diego</option>
        </select>
        <input type="submit" name="upload" value="Upload File" />
    </form></BODY></HTML>

  • #14
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Maybe php has a problem with your $whereto value. Make two folders in the upload directory, one called irvinein-coming and another called sandiego-incoming then change your option values to match the corresponding folder names. Don't put these folders inside of another folder. Make sure they are in the same directory as uploader.php
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #15
    New Coder
    Join Date
    Sep 2003
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts
    still didn't work. i don't know... i'll try to redo the script with what you provided. was there something i'm supposed to change on my end in the following section other then the location: index.php?=$whereto thing?:

    PHP Code:
    /* Add the original filename to our target path. Result is "uploads/filename.extension" */
            
    $target_path $target_path basename($whatfile);
            if(
    move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path))
            {
                
    header("Location: index.php?to=$whereto"); // Directs user back to page of choice
            
    }
            else 


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •