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 6 of 6
  1. #1
    CSS
    CSS is offline
    New Coder
    Join Date
    Jun 2006
    Posts
    40
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Help with Uploader Script

    http://www.enguards.net/un/upload/index.php

    After uploading a file, I get these errors:
    Warning: chmod() [function.chmod]: No such file or directory in /home/sites/enguards.net/public_html/un/upload/config.php on line 57

    Warning: Cannot modify header information - headers already sent by (output started at /home/sites/enguards.net/public_html/un/upload/config.php:57) in /home/sites/enguards.net/public_html/un/upload/config.php on line 68



    Here is config.php:
    PHP Code:
    <?
        $allow_file_deletion 
    true// To allow visitors to delete files, leave this at true; otherwise, change it to false

        
    $file_extensions = array(".gif"".png"".mng"); // Add or delete the file extensions you want to allow

        
    $file_extensions_list ".gif, .png, .mng"// Type the same as above, without the quotes separating them

        
    $max_length 30// The maximum character length for a file name

        
    $maximum_file_size "51200"// In bytes

        
    $upload_log_file "log.txt"// Change this to the log file you want to use



        
    $folder_directory "http://".$_SERVER["HTTP_HOST"].dirname($_SERVER["PHP_SELF"]);
        
    $message "";
        
    $set_chmod 0;
        
    $site_uri "http://".$_SERVER["HTTP_HOST"].$_SERVER["PHP_SELF"];
        
    $upload_directory "files/";
        
    $upload_uri $folder_directory."files/";

        if(
    $allow_file_deletion == true$status "enabled";
        else 
    $status "disabled";

        if(
    $_REQUEST["delete"] && $allow_file_deletion) {
        
    $resource fopen($upload_log_file,"a");
        
    fwrite($resource,date("F d, Y / h:i:sa")." - ".$_REQUEST["delete"]." deleted by ".$_SERVER["REMOTE_ADDR"]."\n");
        
    fclose($resource);

        if(
    strpos($_REQUEST["delete"],"/.") > 0);
        elseif(
    strpos($_REQUEST["delete"],$upload_directory) === false);
        elseif(
    substr($_REQUEST["delete"],0,6) == $upload_directory) {
        
    unlink($_REQUEST["delete"]);
        
    $message "File has been deleted.";
        
    header("Location: $site_uri?message=$message");
        }
        }

        elseif(
    $_FILES["userfile"]) {
        
    $resource fopen($upload_log_file,"a");
        
    fwrite($resource,date("F d, Y / h:i:sa")." - ".$_FILES["userfile"]["name"]." "
        
    .$_FILES["userfile"]["type"]." uploaded by ".$_SERVER["REMOTE_ADDR"]."\n");
        
    fclose($resource);

        
    $file_type $_FILES["userfile"]["type"]; 
        
    $file_name $_FILES["userfile"]["name"];
        
    $file_ext strtolower(substr($file_name,strrpos($file_name,".")));
        
    chmod($upload_uri."".$file_name0755);
        if(
    $_FILES["userfile"]["size"] > $maximum_file_size) {
        
    $message "ERROR: File size cannot be over ".$maximum_file_size." bytes.";
        }

        elseif(
    $file_name == ""$message "ERROR: Please select a file to upload.";
        elseif(
    strlen($file_name $max_length)) $message "ERROR: The maximum length for a file name is ".$max_length." characters.";
        elseif(!
    preg_match("/^[A-Z0-9_.\- ]+$/i",$file_name)) $message "ERROR: Your file name contains invalid characters.";
        elseif(!
    in_array($file_ext$file_extensions))
        
    $message "ERROR: <ins>$file_ext</ins> is not an allowed file extension.";
        else 
    $message upload_file($upload_directory$upload_uri);
        
    header("Location: $site_uri?message=$message");
        }

        elseif(!
    $_FILES["userfile"]);
        else 
    $message "ERROR: Invalid file specified.";

        
    $open opendir($upload_directory);
        
    $uploaded_files "";
        while(
    $file readdir($open)) {
        if(!
    is_dir($file) && !is_link($file)) {
        
    $uploaded_files .= "        <tr>
                    <td style=\"background: #fff; color: #000; text-align: left; width: 70%\"><a href=\"$upload_directory$file\" title=\"$file ("
    .filesize($upload_directory."".$file)." bytes)\">".$file."</a> (".filesize($upload_directory."".$file)." bytes)</td>";
        if(
    $allow_file_deletion)
        
    $uploaded_files .= "
                    <td style=\"background: #fff; color: #000; text-align: right; width: 30%\"><a href=\"?delete=$upload_directory"
    .urlencode($file)."\" title=\"Delete File\">Delete File</a></td>";
        else
        
    $uploaded_files .= "
                    <td style=\"background: #fff; color: #000; text-align: right; width: 30%\"><del><strong>Delete File</strong></del></td>"
    ;
        
    $uploaded_files .= "
                </tr>
                <tr>
                    <td colspan=\"2\" style=\"background: #eee; color: #000; text-align: left; text-indent: 20px\">Uploaded <strong>"
    .date("F d, Y / h:ia"filemtime($upload_directory.$file))."</strong></td>";
        
    $uploaded_files .="
                </tr>
        "
    ;
        }
        }

        function 
    upload_file($upload_directory$upload_uri) {
        
    $file_name $_FILES["userfile"]["name"];
        
    $file_name str_replace(" ","_",$file_name);
        
    $file_path $upload_directory.$file_name;
        
    $temporary $_FILES["userfile"]["tmp_name"];

        
    $result move_uploaded_file($temporary$file_path);
        if(!
    chmod($file_path,0777))
        
    $message "ERROR: A folder to place the files was not found, or the files need to be CHMODed to 777.";
        else 
    $message = ($result)?"File has been uploaded." "An error has occurred.";
        return 
    $message;
        }
    ?>

  • #2
    New to the CF scene
    Join Date
    Aug 2007
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi

    Did you chmod your files directory to at least 755 to be writable?

    Headers ALready Sent I have found is because you have some whitespace or tabs inserted

    Glyn

  • #3
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    The second error seems to be caused by the first, which is being caused by you trying to use chmod() on the file before it's moved to the destination.
    PHP Code:
    chmod($upload_uri."".$file_name0755); 
    That's what it looked like to me, but your code is a mess. You should consider indenting it.

  • #4
    CSS
    CSS is offline
    New Coder
    Join Date
    Jun 2006
    Posts
    40
    Thanks
    0
    Thanked 0 Times in 0 Posts
    How can I fix this? This script is from HotScripts.

  • #5
    CSS
    CSS is offline
    New Coder
    Join Date
    Jun 2006
    Posts
    40
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Anyone?

  • #6
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    I just glanced at it, but the upload_file() functions is chmod()'ing the file, so try just commenting out the first like this: //chmod($upload_uri."".$file_name, 0755); to see if the script functions properly then.


  •  

    Posting Permissions

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