Activity Stream
48,167 MEMBERS
62314 ONLINE
besthostingforums On YouTube Subscribe to our Newsletter besthostingforums On Twitter besthostingforums On Facebook besthostingforums On facebook groups

Results 1 to 8 of 8
  1.     
    #1
    Member

    Default Php:How to prevent from OverWrite ImageUpload File

    Heys, Guys i need Help i want to stop file overwrite when some upload file its check if file already exit same name like sample.jpeg then it will sample1.jpg




    PHP Code: 
    <?php


    require 'db.inc.php';
    if(isset(
    $_POST['up']))
    {
        
        
    function 
    getExtension($name){
        
        
    $pos strpos($name,".");
        
    $len =strlen($name);
        
    $str =substr($name,$pos+1,$len);
        return 
    $str;
        }
        
        
        
        for(
    $i=1$i<=2$i++)
        {
            
    $ext getExtension($_FILES['img'.$i]['name']);
            
        
    $allowed_filetypes = array("jpg","jpeg","png","gif"); 
            
    //if($ext !="jpg" and $ext !="gif" and $ext !="jpeg" and $ext !="png")
                
    if(!in_array($ext,$allowed_filetypes))

            
    //if($ext!= in_array($Allow))
            
    {
                echo 
    "Invlaid File"."<br />";
            
            }
            else
            {
                
            
                echo 
    "Valid File"."<br />";
                
    $path "images/".$_FILES['img'.$i]['name'];
                
    $name $_FILES['img'.$i]['name'];
                
    copy($_FILES['img'.$i]['tmp_name'],$path);
                echo 
    $path."<br />";
                
    mysql_query("insert into img_data (url)values('$name') ")or die($query_error);
            }
            
            }
                    }
    ?>


    ---------- Post added 1st Aug 2012 at 09:56 AM ---------- Previous post was 31st Jul 2012 at 06:21 PM ----------

    solved
    HyDra_92 Reviewed by HyDra_92 on . Php:How to prevent from OverWrite ImageUpload File Heys, Guys i need Help i want to stop file overwrite when some upload file its check if file already exit same name like sample.jpeg then it will sample1.jpg <?php require 'db.inc.php'; if(isset($_POST)) Rating: 5

  2.   Sponsored Links

  3.     
    #2
    Member
    Website's:
    Elite.SO Defendos.com Motionite.com
    Why not added a suffix to all uploaded files? sample_bf87t23r.jpg

    Defendos BETA3 Released! Thread - Official Website

  4.     
    #3
    Member
    Quote Originally Posted by l0calh0st View Post
    Why not added a suffix to all uploaded files? sample_bf87t23r.jpg
    This would be a prefix not a suffix

  5.     
    #4
    Member
    This site is using a hacked database of W junction
    Last edited by Gavo; 4th Jan 2015 at 02:02 PM.

  6.     
    #5
    Member
    i just used rand() and time() Thanks every one

  7.     
    #6
    It begins...
    Quote Originally Posted by MrOSX View Post
    This would be a prefix not a suffix
    Oh dear, you need to go check out wikipedia. What localhost posted was a suffix. A prefix, as the name suggests, is added prior to the actual word. 'Pre'.

  8.     
    #7
    Member
    Website's:
    tehMoviez.com 0Senes.com GeekFaceGames.com
    suffixes are good. But for the name part, you better make it md5 generated. At least it would be homogene and controlled ([a-f0-9]). Then you won't need to worry about special chars or file system issues.

  9.     
    #8
    Respected Member
    Just add the date and time as a prefix or suffix down to the microsecond and you will never have a duplicate and will have the dates to use for sorting.

    That would be better than using random and time.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 14
    Last Post: 2nd Nov 2012, 04:15 AM
  2. Need help code for prevent iFrame
    By MediaStar in forum Web Application/Script Support
    Replies: 2
    Last Post: 7th Jul 2012, 02:52 AM
  3. Review: ImageUpload.ca (18+)
    By HostImage.ca in forum Site Reviews
    Replies: 2
    Last Post: 27th Jan 2012, 01:04 AM
  4. Prevent Your Passwords From RDP Company's
    By sSKKa in forum General Discussion
    Replies: 18
    Last Post: 29th Dec 2011, 03:35 AM
  5. Prevent Template Rip
    By Flash in forum Webmaster Discussion
    Replies: 7
    Last Post: 1st Mar 2009, 03:43 PM

Tags for this Thread

BE SOCIAL