Jump to content


Photo

Which comes first


  • Please log in to reply
5 replies to this topic

#1 .-INSANE-.

.-INSANE-.
  • Members
  • PipPip
  • Member
  • 29 posts

Posted 12 March 2006 - 01:55 AM

ok i was wondering which comes first in my upload script

HTML
<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" />

or the PHP
<?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();
}
}
?>


#2 saiko

saiko
  • Members
  • PipPipPip
  • Advanced Member
  • 37 posts

Posted 12 March 2006 - 12:54 PM

you can do either but i usually do the php after!

#3 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 12 March 2006 - 12:58 PM

Shouldn't really matter where you put the HTML, But placing it after the block of php code should. Heres you 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" />
Note: I chnaged you action attribute value in your form tag. I changed it from:
file:///C|/Documents and Settings/Jordan/My Documents/Photoshop/gameingvideos/fileproc.php to just fileproc.php as when you submit your form the php wont be processed!

#4 saiko

saiko
  • Members
  • PipPipPip
  • Advanced Member
  • 37 posts

Posted 12 March 2006 - 01:03 PM

ill do it like this

<?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();
}
}
?>


#5 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 12 March 2006 - 01:32 PM

I always put the php updates first. That way the results of any changes, such as added, changed or deleted records etc, are displayed in the main body of the page.
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#6 .-INSANE-.

.-INSANE-.
  • Members
  • PipPip
  • Member
  • 29 posts

Posted 12 March 2006 - 11:39 PM

ok thanks for the help




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users