Page 1 of 5
file_exists ?
Posted: Mon Mar 01, 2004 5:12 pm
by mikegotnaild
Hey. I got a problem with this code.
Code: Select all
$imagefile = $_FILES['imagefile']['name'];
$mp3file = $_FILES['mp3file']['name'];
//Check to see weather there is a file in our upload folder with the same name
if (file_exists($_SERVER['DOCUMENT_ROOT'].'/localmm/upload/'.$imagefile)) {
echo "There is already a file called <b>$imagefile</b> on our server. <b>Please rename this file.</b> <br><br>Click the Back button and RE-SUBMIT.";
exit();
}
//Check to see weather there is a file in our upload folder with the same name
if (file_exists($_SERVER['DOCUMENT_ROOT'].'/localmm/upload/'.$mp3file)) {
echo "There is already a file called <b>$mp3file</b> on our server. <b>Please rename this file.</b> <br><br>Click the Back button and RE-SUBMIT.";
exit();
}
This obviously isnt the full script. Even if there isnt a file with the same name as the ones i want to upload it still gives me that error message
Code: Select all
echo "There is already a file called <b>$mp3file</b> on our server. <b>Please rename this file.</b> <br><br>Click the Back button and RE-SUBMIT.";
?>
Posted: Mon Mar 01, 2004 8:16 pm
by mikegotnaild
bump if u dont mind
Posted: Tue Mar 02, 2004 8:10 pm
by mikegotnaild
hmm
Posted: Tue Mar 02, 2004 8:27 pm
by markl999
Wel, unless you've discovered a bug in file_exists() (which i doubt after the length of time it's been in use

) then it must be either :
1. The file does exist
2. $mp3file isn't set
3. A symlink problem
I'd make sure you have error_reporting(E_ALL) at the top of the script, that should rule out number 2, number 1 is easy to debug .. just go look

Number 3 i wouldn't have thought would be a problem, but check that $_SERVER['DOCUMENT_ROOT'] is a 'real' path and not a symlink of some kind.
Posted: Tue Mar 02, 2004 8:59 pm
by mikegotnaild
1. File Doesnt exist for sure.
well $_SERVER['DOCUMENT_ROOT'].'/localmm/upload/' is the same thing i use for uploading.. and the files uploaded correctly to that directory before i started this new file_exists check. i will do what you said.
Posted: Tue Mar 02, 2004 9:06 pm
by markl999
Just another thing to check, is there anything strange about the file name that are being uploaded? ie Do they have any special chars in them, like spaces etc.. ?
Posted: Tue Mar 02, 2004 9:07 pm
by mikegotnaild
nope
Posted: Tue Mar 02, 2004 9:10 pm
by markl999
Hmm..are you wearing blue socks? File uploads only work if you are wearing blue socks.</running out of ideas>

Posted: Tue Mar 02, 2004 9:13 pm
by mikegotnaild
i put error_reporting(E_ALL); in my script and tried it but the only out put was that error message i made for the check
Code: Select all
echo "There is already a file called <b>$mp3file</b> on our server. <b>Please rename this file.</b> <br><br>Click the Back button and RE-SUBMIT.";
\
Would u like my full script? Oh and $mp3file doesnt out put anything when that error shows up.. It just says
There is already a file called on our server. please rename this file
Click Back button and RE-SUBMIT.
Posted: Tue Mar 02, 2004 9:15 pm
by markl999
Would u like my full script?
Sure.
Posted: Tue Mar 02, 2004 9:17 pm
by mikegotnaild
Code: Select all
<?
error_reporting(E_ALL);
//MySQL Variables
$host = "host";
$login_name = "login";
$password = "pass";
//Connecting to MYSQL
MySQL_connect("$host","$login_name","$password");
//Select the database
MySQL_select_db("bandsandmembers") or die("Could not select database");
//Assign contents of form to variables
$bandname = $_POST['band_name'];
$description = $_POST['description'];
$history = $_POST['history'];
$influences = $_POST['influences'];
$genra = $_POST['genra'];
$email = $_POST['email'];
$website = $_POST['website'];
$imagefile = $_FILES['imagefile']['name'];
$mp3file = $_FILES['mp3file']['name'];
$types = array("image/gif","image/jpeg","image/bmp","image/pjpeg","image/x-windows-bmp");
$types2 = array("audio/mpeg","audio/mp3","audio/x-mpeg-3","audio/x-mp3","audio/m3u","audio/x-m3u","application/x-compressed","application/zip","multipart/x-zip","application/x-troff-msvideo","video/msvideo","video/x-msvideo","application/x-compressed","video/avi","video/mpeg","audio/mpeg3","video/mpeg","video/x-mpeg");
//This is the File upload part
$uploaddir = $_SERVER['DOCUMENT_ROOT'].'/localmm/upload/';
$uploadfile1 = $uploaddir . $_FILES['imagefile']['name'];
$uploadfile2 = $uploaddir . $_FILES['mp3file']['name'];
//Check to see weather there is a file in our upload folder with the same name
if(file_exists($uploaddir . $imagefile)) {
echo "There is already a file called <b>$imagefile</b> on our server. <b>Please rename this file.</b> <br><br>Click the Back button and RE-SUBMIT.";
$uploaded = glob($_SERVER['DOCUMENT_ROOT'].'/localmm/upload/*.*');
foreach($uploaded as $up){
if($up == $imagefile){
echo '<b>'.$up.'</b><br />';
} else {
echo $up.'<br />';
}
}
exit();
}
//Check to see weather there is a file in our upload folder with the same name
if(file_exists($uploaddir . $mp3file)) {
echo "There is already a file called <b>$mp3file</b> on our server. <b>Please rename this file.</b> <br><br>Click the Back button and RE-SUBMIT.";
$uploaded = glob($_SERVER['DOCUMENT_ROOT'].'/localmm/upload/*.*');
foreach($uploaded as $up){
if($up == $mp3file){
echo '<b>'.$up.'</b><br />';
} else {
echo $up.'<br />';
}
}
exit();
}
if (in_array($_FILES['imagefile']['type'], $types)){
move_uploaded_file($_FILES['imagefile']['tmp_name'], $uploadfile1);
}else{
echo "There was an error when uploading. Your file could have been too big. or Check to see if you uploaded the correct file type. Allowd file types are. .gif, .jpg, .jpeg, .bmp";
}
if (in_array($_FILES['mp3file']['type'], $types2)){
move_uploaded_file($_FILES['mp3file']['tmp_name'], $uploadfile2);
}else{
echo "There was an error when uploading. Your file could have been too big. or Check to see if you uploaded the correct file type. Allowd file types are. .mp3, .avi, .mpg, .mpeg, .zip";
}
$sql = "INSERT INTO $genra (band_name, description, history, influences, genra, email, website, imagefile, mp3file) VALUES ('$bandname','$description','$history','$influences','$genra','$email','$website','$imagefile','$mp3file')";
$result = mysql_query($sql);
//Code to check if statement executed properly and display message
if ($result) {
} else {
echo("An error has occured");
}
//Close connection with MySQL
MySQL_close()
?>
Posted: Tue Mar 02, 2004 9:22 pm
by markl999
hmm..all looks ok. Don't know if this will help, but you could try this extra debugging.
Code: Select all
if (file_exists($_SERVER['DOCUMENT_ROOT'].'/localmm/upload/'.$mp3file)) {
echo "There is already a file called <b>$mp3file</b> on our server. <b>Please rename this file.</b> <br><br>Click the Back button and RE-SUBMIT.";
$uploaded = glob($_SERVER['DOCUMENT_ROOT'].'/localmm/upload/*.*');
foreach($uploaded as $up){
if($up == $mp3file){
echo '<b>'.$up.'</b><br />';
} else {
echo $up.'<br />';
}
}
exit();
}
This should just list the files already in the upload dir and highlight any matching ones in bold. Shouldn't show any suprises but it's worth a go

Posted: Tue Mar 02, 2004 9:22 pm
by d3ad1ysp0rk
what happens when u try using
if(file_exists($uploaddir . $imagefile)){
??
Posted: Tue Mar 02, 2004 9:24 pm
by mikegotnaild
LiLpunkSkateR wrote:what happens when u try using
if(file_exists($uploaddir . $imagefile)){
??
I had thought about doing that but someone gave me the code snippet im using right now and since $uploaddir 's value means the same as what i have down i didnt think it would matter. But ill try the extra debugging and if(file_exists($uploaddir . $imagefile)){
ILL...BE.. BACK
Posted: Tue Mar 02, 2004 9:34 pm
by mikegotnaild
still doesnt work. *shakes head*
I shall edit my post with full code to the new code u guys gave me. just for the heck of it
There is already a file called $imagefile on our server. Please rename this file.
and i get:
"There is already a file called on our server. Please rename this file."
So this means $imagefile isnt putting out anything... Any ideas?