Page 5 of 5

Posted: Wed Mar 03, 2004 1:02 am
by markl999
It doesn't. Just do this...

Code: Select all

<?php
error_reporting(E_ALL);
//MySQL Variables
$host = "host";
$login_name = "login";
$password = "pass";

//Connecting to MYSQL
MySQL_connect("$host","$login_name","$password") or die(mysql_error());

//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'];

if(empty($_FILES['imagefile']['name'])){
  echo 'No image was uploaded.<br />';
}
if(empty($_FILES['mp3file']['name'])){
  echo 'No mp3 was uploaded.<br />';
}

//Check to see weather there is a file in our upload folder with the same name
if(!empty($_FILES['imagefile']['name']) && 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.";
  exit;
}

//Check to see weather there is a file in our upload folder with the same name
if(!empty($_FILES['mp3file']['name'])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.";
  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')";
mysql_query($sql) or die(mysql_error());

//Close connection with MySQL
mysql_close()
?>

Posted: Wed Mar 03, 2004 1:04 am
by mikegotnaild
nevermind

Posted: Wed Mar 03, 2004 1:08 am
by markl999
ok, i'll just forget the hours i've put into this :p
Let us all know how you get on.

Posted: Wed Mar 03, 2004 1:12 am
by mikegotnaild
i meant nevermind i understood

Posted: Wed Mar 03, 2004 1:15 am
by markl999
I apologize, i'm just tired, ignore me ;)

Posted: Wed Mar 03, 2004 1:18 am
by mikegotnaild
so do i put the input hidden back in my form with the code u just gave me? Or leave it out?

Posted: Wed Mar 03, 2004 1:22 am
by markl999
Just leave it out. The code i posted will probably warn about the file type being wrong or the file being to big, but it should also at least tell you if either an image or an mp3 failed to upload.
So if you upload an mp3 and it shows the 'no mp3 was uploaded' message then it confirms you have file size problems.

Posted: Wed Mar 03, 2004 1:27 am
by mikegotnaild
OK the image uploaded to the upload folder correctly and here is my output:

No mp3 was uploaded.
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

Were getting somewhere !

Posted: Wed Mar 03, 2004 1:28 am
by markl999
ok, and if you upload an mp3 aswell as an image, what does it say, if it says the same then you have file size problems. You can prove it by uploading a small mp3, say something under 2M and you shouldn't get that message.
I've no idea why you should get that message if the upload limit is 8M and you are uploading n mp3 under that size.

Posted: Wed Mar 03, 2004 1:38 am
by mikegotnaild
Nope they both uploaded.. the mp3 file i uploaded was 3.10 mb too. And there was no output

Posted: Wed Mar 03, 2004 1:39 am
by mikegotnaild
Do you think i can use the hidden fields in my form now?

Posted: Wed Mar 03, 2004 1:41 am
by markl999
Well, i still don't think you can use 2, but try it, if it fails again then remove them or just have one hidden field that has a size that covers both images and mp3's.

Posted: Wed Mar 03, 2004 1:46 am
by mikegotnaild
So if i use only 1 hidden field with a max size of 6.5 mb that will check weather both of the files to upload put together are less than 6.5 mb or does it check them individually weather they are 6.5 or less?

Posted: Wed Mar 03, 2004 1:49 am
by markl999
Should check them individually.

Posted: Wed Mar 03, 2004 1:54 am
by mikegotnaild
Oh well i cant have people uploading monster sized images lol. I would like a 200 kb max on images. I put both fields and it worked. Thanks mark. Now i just need to get some kind of thing that shows the upload progress.