Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

 
 
Thread Tools Display Modes
Prev Previous Post in Thread   Next Post in Thread Next
Old Feb 22nd, 2005, 11:31 AM   #1
TCStyle
Programmer
 
Join Date: Jan 2005
Location: Albany, NY
Posts: 43
Rep Power: 0 TCStyle is on a distinguished road
file_exists() problemo

We'll I'm programming a file uploader with php. I found a simple script on the net and I'm adding onto it. I've run into a problem though, my if statement that contains my file_exists check isn't working. Heres the code I have:

<?php
$filename = str_replace(' ', '', $_FILES['upload_file']['name']);
$tblw = strlen($filename);
$ext = substr($filename, $tblw-3, $tblw);
$filesize= $HTTP_POST_FILES['upload_file']['size'];
$name= $_POST['FName'];
$stripName= strip_tags($name);
if ($filesize > 262144) {
echo "Sorry your file size is to big!";
echo "<br />";
echo "File size limit is 262144 bytes (or .25 MB)";
}
if ($filesize = 0) {
echo "No file was uploaded!";
}
if (file_exists("/upload/".$stripName)) {
echo "A file with this exact name already exists. Please go back and rename your file!";
}
if ($ext == 'png' OR $ext == 'gif' OR $ext == 'jpg' || $filesize <= 262144 || $filesize != 0 || !file_exists("/upload/".$stripName)) {
$uploaddir = "htdocs/upload/";
$uploadfile = $uploaddir . $stripName . "." . $ext;
$file = 'htdocs/upload/' . $stripName . '.' . $ext;
move_uploaded_file($_FILES['upload_file']['tmp_name'], $uploadfile);
echo "File was uploaded successfully!";
};
?>

Basically I want it so that if a file with the same name tries to get uploaded to my "upload" folder, then and error message comes up. But, for some reason, if the file exists, it just says "file was uploaded sucessfully", and doesn't overwrite the file that was already there? Any help is apperciated!
TCStyle is offline   Reply With Quote
 

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 1:27 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC