It might be better to copy the form and the upload file to .phps files and post links to them rather than keep reposting it here
file_exists ?
Moderator: General Moderators
-
mikegotnaild
- Forum Contributor
- Posts: 173
- Joined: Sat Feb 14, 2004 5:59 pm
Before i did this error checking i could upload any file size within my specifyed limits on my form... All i wanna do is do a measaly little file_exists check and its getting complicated.
Last edited by mikegotnaild on Wed Mar 03, 2004 12:19 am, edited 1 time in total.
-
mikegotnaild
- Forum Contributor
- Posts: 173
- Joined: Sat Feb 14, 2004 5:59 pm
No, the point is you couldn't upload any file size, it just looked like you could because you didn't have the error checking at it bombed out saying the file existed because $mp3file was empty and your file_exists() check would always be true.
The file size of the mp3 is your problem, as proved by the fact that you can/could upload mp3 less than 2M in size.
Removing those 2 hidden input fields from the form should be enough to allow you to upload 8M images and mp3's, i'm confused why it doesn't.
What does a simple test file with the following in it output?
edit
ok, the phpinfo() says 8M, so i've no idea why removing just those 2 hidden fields shouldn't make it all now work (and remove that .htaccess if you still have it around).
Oh, also, who set the upload_tmp_dir to /localmm/uploadtmp/ .. that doesn't look right to me.
The file size of the mp3 is your problem, as proved by the fact that you can/could upload mp3 less than 2M in size.
Removing those 2 hidden input fields from the form should be enough to allow you to upload 8M images and mp3's, i'm confused why it doesn't.
What does a simple test file with the following in it output?
Code: Select all
<?php
echo ini_get('upload_max_filesize');
?>ok, the phpinfo() says 8M, so i've no idea why removing just those 2 hidden fields shouldn't make it all now work (and remove that .htaccess if you still have it around).
Oh, also, who set the upload_tmp_dir to /localmm/uploadtmp/ .. that doesn't look right to me.
-
mikegotnaild
- Forum Contributor
- Posts: 173
- Joined: Sat Feb 14, 2004 5:59 pm
-
mikegotnaild
- Forum Contributor
- Posts: 173
- Joined: Sat Feb 14, 2004 5:59 pm
the form without the hidden fields
The upload script.
Code: Select all
<FORM enctype="multipart/form-data" ACTION="http://naild.com/localmm/modules.php?name=Band_Submit&file=upload" METHOD="POST">
Band Name:<br>
<input type="text" name="band_name"size=40><br>
Description:<br>
<textarea cols=65 rows=10 name="description"></textarea><br>
History:<br>
<textarea cols=65 rows=10 name="history"></textarea><br>
Influences:<br>
<input type="text" name="influences"size=65><br>
<br>
Select Genra:<br>
<select name="genra"><br>
<option>------Click Here-----</option>
<option value="Acoustic">Acoustic</option>
<option value="Alternative">Alternative</option>
<option value="Blues">Blues</option>
<option value="Christian">Christian</option>
<option value="Classic_Rock">Classic Rock</option>
<option value="Classical">Classical</option>
<option value="Country">Country</option>
<option value="Cover_Bands">Cover Bands</option>
<option value="Death_Metal">Death Metal</option>
<option value="Disc_Jockey">Disc Jockey</option>
<option value="Easy_Listening">Easy Listening</option>
<option value="Electronic">Electronic</option>
<option value="Emo">Emo</option>
<option value="Experimental">Experimental</option>
<option value="Folk">Folk</option>
<option value="Funk">Funk</option>
<option value="Gospel">Gospel</option>
<option value="Gothic">Gothic</option>
<option value="Grunge">Grunge</option>
<option value="Hardcore">Hardcore</option>
<option value="Hip_Hop">Hip Hop</option>
<option value="Instrumental">Instrumental</option>
<option value="Jazz">Jazz</option>
<option value="Metal">Metal</option>
<option value="Modern_Rock">Modern Rock</option>
<option value="Progressive">Progressive</option>
<option value="Punk">Punk</option>
<option value="Rap">Rap</option>
<option value="Reggae">Reggae</option>
<option value="Rock">Rock</option>
<option value="Ska">Ska</option>
<option value="Speed_Metal">Speed Metal</option>
<option value="Swing">Swing </option>
</select>
<br>
<br>
Email:<br>
<input type="text" name="email"size=40><br>
<br>
Website:<br>
<input type="text" name="website"size=40 value="http://"><br>
<br>
Upload files:<BR>
<i>Click Browse than browse to your file</i><br>
Image File: (200 kb max)<br>
<INPUT TYPE="FILE" NAME="imagefile" SIZE="50">  <i>(IF you do select an image file or mp3 file to upload, UPLOAD TIMES MAY VARY. The page will appear to be loading, but thats the upload in progress)</i><BR>
Mp3/.avi/.mpg/.mpeg/.zip File: (6MB max)<br>
<INPUT TYPE="FILE" NAME="mp3file" SIZE="50"><BR>
<INPUT TYPE="submit" name="submit" value="submit"><BR>
</form>Code: Select all
<?
error_reporting(E_ALL);
//MySQL Variables
$host = "?";
$login_name = "?";
$password = "?";
//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'];
$dump = var_dump($_FILES['mp3file']);
echo "$dump";
$imglimit = 200000; //200K
$mp3limit = 6000000; //6M
if($_FILES['imagefile']['size'] > $imglimit){
echo 'Image is too big'; exit;
}
if($_FILES['mp3file']['size'] > $mp3limit){
echo 'Mp3 is too big'; exit;
}
//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()
?>-
mikegotnaild
- Forum Contributor
- Posts: 173
- Joined: Sat Feb 14, 2004 5:59 pm
Do you mean before i started the file_exists() checking? Because uploads worked just fine before i started that. But now even if i ONLY try to upload an image file i still get that error.markl999 wrote:Weird, an upload_tmp_dir of /localmm/uploadtmp/ looks weird to me as it suggests a root path, and not a path in your document root.
When you upload an image (forget the mp3) does it 'work ok' ? i.e put a temp file in /localmm/uploadtmp/ and move it to /localmm/upload ok ?
Code: Select all
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.";
Last edited by mikegotnaild on Wed Mar 03, 2004 12:38 am, edited 1 time in total.
That's because the mp3 is too big and didn't get uploaded, this is proved by a var_dump($_FILES['mp3file']) which is empty, and you CAN upload an mp3 less than 2M. You should be checking it got uploaded ok first before the file_exists() with something like :
if(empty($_FILES['mp3file']['name'])){ echo 'The mp3 file failed to upload'; exit; }
Dunno what else to tell you now, if you've removed those 2 hidden fields then i don't know what the problem is *shrug*
if(empty($_FILES['mp3file']['name'])){ echo 'The mp3 file failed to upload'; exit; }
Dunno what else to tell you now, if you've removed those 2 hidden fields then i don't know what the problem is *shrug*
-
mikegotnaild
- Forum Contributor
- Posts: 173
- Joined: Sat Feb 14, 2004 5:59 pm
*sigh*
Because, you do not check if the mp3 file was uploaded or not, you simply proceed to do a file_exists on $_FILES['mp3file']['name'] so if you didn't even upload one that will be empty and you'll just end up checking if /localmm/upload exists, which of course it does.
The point is you never check if you uploaded one or not, you go straight to checking if $_FILES['mp3file']['name'] exists or not without first checking it was even uploaded.
Because, you do not check if the mp3 file was uploaded or not, you simply proceed to do a file_exists on $_FILES['mp3file']['name'] so if you didn't even upload one that will be empty and you'll just end up checking if /localmm/upload exists, which of course it does.
The point is you never check if you uploaded one or not, you go straight to checking if $_FILES['mp3file']['name'] exists or not without first checking it was even uploaded.
-
mikegotnaild
- Forum Contributor
- Posts: 173
- Joined: Sat Feb 14, 2004 5:59 pm
-
mikegotnaild
- Forum Contributor
- Posts: 173
- Joined: Sat Feb 14, 2004 5:59 pm
No no no 
The reason the file_exists is failing is because the file never got uploaded in the first place, so $_FILES['mp3file']['name'] is empty so your file_exists() always returns true.
If you var_dump($_FILES['mp3file']); BEFORE you do any file_exists() stuff you'll see it's empty, so the problem is why didn't it get uploaded? And as you can upload an mp3 less than 2M then it has to be a file size restriction.
Basically you need to work out, why, when you do upload an mp3, $_FILES['mp3file'] is empty.
Maybe i'm just not explaining it clearly, sorry if that's the case
The reason the file_exists is failing is because the file never got uploaded in the first place, so $_FILES['mp3file']['name'] is empty so your file_exists() always returns true.
If you var_dump($_FILES['mp3file']); BEFORE you do any file_exists() stuff you'll see it's empty, so the problem is why didn't it get uploaded? And as you can upload an mp3 less than 2M then it has to be a file size restriction.
Basically you need to work out, why, when you do upload an mp3, $_FILES['mp3file'] is empty.
Maybe i'm just not explaining it clearly, sorry if that's the case
-
mikegotnaild
- Forum Contributor
- Posts: 173
- Joined: Sat Feb 14, 2004 5:59 pm