Jump to content

WarMacheen

New Members
  • Posts

    4
  • Joined

  • Last visited

WarMacheen's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I have the following simple form, when I upload it goes back to upload.html, which is fine, but nothing is uploaded to the "uploads/" folder. No errors if it is the wrong file type and no results if it is the correct file type <form name="uploadForm" method="post" action="upload.php" enctype="multipart/form-data"> Select an mp3 file only: <br> <input name="user_file" type="file" /><br> <input type="submit" name="upload" value="Upload"> </form> and the following PHP <?php header("*****************************"); echo "Please wait while we attempt to upload your file...<br><br>"; $target_path = "uploads/"; $flag = 0; $filename = $_FILES['uploadedfile']['name']; $filesize = $_FILES['uploadedfile']['size']; $mimetype = $_FILES['uploadedfile']['type']; $filename = htmlentities($filename); $filesize = htmlentities($filesize); $mimetype = htmlentities($mimetype); $target_path = $target_path . basename( $filename ); if($filename != ""){ echo "Beginning upload process for file named: ".$filename."<br>"; echo "Filesize: ".$filesize."<br>"; echo "Type: ".$mimetype."<br><br>"; } $hashedfilename = md5($filename.time()); $hashedfilename = $hashedfilename.".mp3"; //Check for empty file if($filename == ""){ $error = "No File Exists!"; $flag = $flag + 1; } $existname = "uploads/".$hashedfilename; if(file_exists($existname)){ if($flag == 0){ $error = "Your file already exists on the server! Please choose another file to upload or rename the file on your computer and try uploading it again!"; } $flag = $flag + 1; } //Whitelisted files $whitelist = array(".mp3"); foreach ($whitelist as $ending) { if(substr($filename, -(strlen($ending))) != $ending) { $error = "The file type or extention you are trying to upload is not allowed! You can only upload MP3 files to the server!"; $flag++; } } if($filesize > 9920600){ //File is too large if($flag == 0){ $error = "The file you are trying to upload is too large! Please upload a smaller MP3 file or encode your file with a lower bitrate."; } $flag = $flag + 1; } if($filesize < 1048600){ //File is too small if($flag == 0){ $error = "The file you are trying to upload is too small! Your file has been marked as suspicious because our system has determined that it is too small to be a valid MP3 file. Valid MP3 files must be bigger than 1 MB and smaller than 6.5 MB."; } $flag = $flag + 1; } //Check the mimetype of the file if($mimetype != "audio/x-mp3" and $mimetype != "audio/mpeg"){ if($flag == 0){ $error = "The file you are trying to upload does not contain expected data. Are you sure that the file is an MP3?"; } $flag = $flag + 1; } //Check that the file really is an MP3 file by reading the first few characters of the file $f = @fopen($_FILES['uploadedfile']['tmp_name'],'r'); $s = @fread($f,3); @fclose($f); if($s != "ID3"){ if($flag == 0){ $error = "The file you are attempting to upload does not appear to be a valid MP3 file."; } $flag++; } //All checks are done move the file if($flag == 0){ if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { //Change the filename to MD5 hash and FORCE a MP3 extention. if(@file_exists("uploads/".$filename)){ //Rename the file to an MD5 version rename("uploads/".$filename, "uploads/".$hashedfilename); echo "The file ". basename( $filename ). " has been uploaded. Your file is <a href='uploads/$hashedfilename'>here</a>."; } else{ echo "There was an error uploading the file, please try again!"; } } else{ echo "There was an error uploading the file, please try again!"; } } else { echo "File Upload Failed!<br>"; if($error != ""){ echo $error; } } ?>
  2. The encoding was the problem, thank you. I changed to UTF-8 without signature, works
  3. I've been rearranging and changing things for a few hours and I can't get past this issue Warning: Cannot modify header information - headers already sent by (output started at /****/****/****/****/php/mailer.php:1) in /****/****/****/****/php/mailer.php on line 27 If I comment out the thanks.html header there isn't an error, but the code also doesn't redirect to the correct html page. I've also verified that there isn't any white space issues at the beginning and end of the code block <?php $myemail = "[email protected]"; $first_name = check_input($_POST['first_name'], "Enter your first name"); $last_name = check_input($_POST['last_name'], "Enter your last name"); $subject = "email from Dulles ISAC contact form"; $email = check_input($_POST['email']); $comments = check_input($_POST['comments'], "Write your message"); if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email)) { show_error("E-mail address not valid"); } $message = " First Name: $first_name Lirst Name: $last_name E-mail: $email Comments: $comments "; mail($myemail, $subject, $message); header('Location:thanks.html'); exit(); function check_input($data, $problem='') { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); if ($problem && strlen($data) == 0) { show_error($problem); } return $data; } function show_error($myError) { ?> <html> <body> <p>Please correct the following error:</p> <strong><?php echo $myError; ?></strong> <p>Hit the back button and try again</p> </body> </html> <?php exit(); } ?>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.