Results 1 to 8 of 8
-
1st Aug 2012, 09:56 AM #1OPMember
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 ----------
solvedHyDra_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
-
1st Aug 2012, 11:20 AM #2MemberWebsite's:
Elite.SO Defendos.com Motionite.comWhy not added a suffix to all uploaded files? sample_bf87t23r.jpg
-
1st Aug 2012, 11:25 AM #3Member
-
1st Aug 2012, 11:29 AM #4Member
This site is using a hacked database of W junction
Last edited by Gavo; 4th Jan 2015 at 02:02 PM.
-
5th Aug 2012, 01:25 PM #5OPMember
i just used rand() and time() Thanks every one
-
5th Aug 2012, 01:41 PM #6It begins...
-
5th Aug 2012, 02:06 PM #7MemberWebsite's:
tehMoviez.com 0Senes.com GeekFaceGames.comsuffixes 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.
JokerHacker Blog
JokerHacker PHP coding Service // back again!
CurlAxel PHP Download Accelerator
hardly remembering the milk :p
-
5th Aug 2012, 04:53 PM #8Respected 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.
Sponsored Links
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Similar Threads
-
What steps should to take on File-hosts by KWWH to prevent scam?
By sohom in forum File Host DiscussionReplies: 14Last Post: 2nd Nov 2012, 04:15 AM -
Need help code for prevent iFrame
By MediaStar in forum Web Application/Script SupportReplies: 2Last Post: 7th Jul 2012, 02:52 AM -
Review: ImageUpload.ca (18+)
By HostImage.ca in forum Site ReviewsReplies: 2Last Post: 27th Jan 2012, 01:04 AM -
Prevent Your Passwords From RDP Company's
By sSKKa in forum General DiscussionReplies: 18Last Post: 29th Dec 2011, 03:35 AM -
Prevent Template Rip
By Flash in forum Webmaster DiscussionReplies: 7Last Post: 1st Mar 2009, 03:43 PM
themaPoster - post to forums and...
Version 5.22 released. Open older version (or...