Jump to content

Which comes first


.-INSANE-.

Recommended Posts

ok i was wondering which comes first in my upload script

HTML
[code]
<form enctype="multipart/form-data" action="file:///C|/Documents and Settings/Jordan/My Documents/Photoshop/gameingvideos/fileproc.php" method="POST">
  <p>
    <input name="file" type="file" />
    <br />
    By uploading you file you agree to the <a href="Terms Of Service.php" class="style1 style1">Terms Of Service</a>
    <input type="submit" value="Submit" />
[/code]

or the PHP
[code]
<?PHP
if($_POST['submit']){
$directory = "/home/username/public_html/files/";
$max_file_size = "1000000";
$allowedfile[] = "video/x-ms-wmv";  
$allowedfile[] = "video/x-msvideo";  
$allowedfile[] = "video/mpeg";  
$allowedfile[] = "video/quicktime";  
if (is_uploaded_file($_FILES["file"]["tmp_name"])) {    
    if($_FILES["file"]["size"]>$max_file_size) {        
        $is_uploaded = "failed";      
        echo 'Sorry, this file is too large. The maximum filesize is '.$max_file_size.' bytes, although your file is '.$_FILES["file"]["size"].'. ';        
        exit();    
        }    
        if(!in_array($_FILES["file"]["type"],$allowedfile)) {        
            $is_uploaded = "failed";        
            echo 'Sorry, wrong file type, "'.$_FILES["file"]["type"].'" is not allowed. ';      
            exit();  
        }    
        if(file_exists($directory.$_FILES["file"]["name"])) {        
            $is_uploaded = "failed";        
            echo 'Sorry, this file already exists. ';        
            exit();
        if($is_uploaded!="failed") {
               $replace = array("$","%","#","@","!","&","^","*","(",")","-");
            $new = str_replace($replace,"",$_FILES["file"]["name"]);
            $fileName = str_replace(" " , "_" , $new);

        if(! is_dir($directory)){
                mkdir($directory,0777);
            }
        if (move_uploaded_file($_FILES["file"]["tmp_name"], $directory.$fileName)) {
                echo "Your file, ". $fileName ." has successfully been uploaded!  Click <a href=\"".$directory.$fileName."\">Here</a> to view your file.";
            }
    else {
        echo 'Sorry, your file has not uploaded.';
        exit();
        }
    }
} else {
    echo 'There has been an unknown error while uploading';
    exit();
}
}
?>[/code]
Link to comment
Share on other sites

Shouldn't really matter where you put the HTML, But placing it after the block of php code should. Heres you code:
[code]<?PHP
if($_POST['submit']){
$directory = "/home/username/public_html/files/";
$max_file_size = "1000000";
$allowedfile[] = "video/x-ms-wmv";  
$allowedfile[] = "video/x-msvideo";  
$allowedfile[] = "video/mpeg";  
$allowedfile[] = "video/quicktime";  
if (is_uploaded_file($_FILES["file"]["tmp_name"])) {    
    if($_FILES["file"]["size"]>$max_file_size) {        
        $is_uploaded = "failed";      
        echo 'Sorry, this file is too large. The maximum filesize is '.$max_file_size.' bytes, although your file is '.$_FILES["file"]["size"].'. ';        
        exit();    
        }    
        if(!in_array($_FILES["file"]["type"],$allowedfile)) {        
            $is_uploaded = "failed";        
            echo 'Sorry, wrong file type, "'.$_FILES["file"]["type"].'" is not allowed. ';      
            exit();  
        }    
        if(file_exists($directory.$_FILES["file"]["name"])) {        
            $is_uploaded = "failed";        
            echo 'Sorry, this file already exists. ';        
            exit();
        if($is_uploaded!="failed") {
               $replace = array("$","%","#","@","!","&","^","*","(",")","-");
            $new = str_replace($replace,"",$_FILES["file"]["name"]);
            $fileName = str_replace(" " , "_" , $new);

        if(! is_dir($directory)){
                mkdir($directory,0777);
            }
        if (move_uploaded_file($_FILES["file"]["tmp_name"], $directory.$fileName)) {
                echo "Your file, ". $fileName ." has successfully been uploaded!  Click <a href=\"".$directory.$fileName."\">Here</a> to view your file.";
            }
    else {
        echo 'Sorry, your file has not uploaded.';
        exit();
        }
    }
} else {
    echo 'There has been an unknown error while uploading';
    exit();
}
}
?>
<form enctype="multipart/form-data" action="fileproc.php" method="POST">
  <p>
    <input name="file" type="file" />
    <br />
    By uploading you file you agree to the <a href="Terms Of Service.php" class="style1 style1">Terms Of Service</a>
    <input type="submit" value="Submit" />
[/code]
Note: I chnaged you action attribute value in your form tag. I changed it from:
[i]file:///C|/Documents and Settings/Jordan/My Documents/Photoshop/gameingvideos/fileproc.php[/i] to just [i]fileproc.php[/i] as when you submit your form the php wont be processed!
Link to comment
Share on other sites

ill do it like this

[code]
<?PHP
if(!isset($_POST['submit']){

echo <<<html
<form enctype="multipart/form-data" action="fileproc.php" method="POST">
  <p>
    <input name="file" type="file" />
    <br />
    By uploading you file you agree to the <a href="Terms Of Service.php" class="style1 style1">Terms Of Service</a>
    <input type="submit" value="Submit" />
html;

}elseif(isset($_POST['submit'])){
$directory = "/home/username/public_html/files/";
$max_file_size = "1000000";
$allowedfile[] = "video/x-ms-wmv";  
$allowedfile[] = "video/x-msvideo";  
$allowedfile[] = "video/mpeg";  
$allowedfile[] = "video/quicktime";  
if (is_uploaded_file($_FILES["file"]["tmp_name"])) {    
    if($_FILES["file"]["size"]>$max_file_size) {        
        $is_uploaded = "failed";      
        echo 'Sorry, this file is too large. The maximum filesize is '.$max_file_size.' bytes, although your file is '.$_FILES["file"]["size"].'. ';        
        exit();    
        }    
        if(!in_array($_FILES["file"]["type"],$allowedfile)) {        
            $is_uploaded = "failed";        
            echo 'Sorry, wrong file type, "'.$_FILES["file"]["type"].'" is not allowed. ';      
            exit();  
        }    
        if(file_exists($directory.$_FILES["file"]["name"])) {        
            $is_uploaded = "failed";        
            echo 'Sorry, this file already exists. ';        
            exit();
        if($is_uploaded!="failed") {
               $replace = array("$","%","#","@","!","&","^","*","(",")","-");
            $new = str_replace($replace,"",$_FILES["file"]["name"]);
            $fileName = str_replace(" " , "_" , $new);

        if(! is_dir($directory)){
                mkdir($directory,0777);
            }
        if (move_uploaded_file($_FILES["file"]["tmp_name"], $directory.$fileName)) {
                echo "Your file, ". $fileName ." has successfully been uploaded!  Click <a href=\"".$directory.$fileName."\">Here</a> to view your file.";
            }
    else {
        echo 'Sorry, your file has not uploaded.';
        exit();
        }
    }
} else {
    echo 'There has been an unknown error while uploading';
    exit();
}
}
?>
[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.