Jump to content

this code doesn't work on localhost but does on remote host


attaboy

Recommended Posts

I have code to upload mp3 to a server when run from my godaddy account it works fine when I run locally I get "invalid file" which is a message generated from the script.  I looked through my php.ini file amd dindn't find anything, maybe I just don't know what to look for.  I'm sure there must be a setting somewhere in some configuration file that would fix my problem.

here is the code

 

 

<!doctype html>
<html>
<head>
<title> upload songs </title>
</head>
<body>
<form action="upload_songs.php" method="post" enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file"><br>
<input type="submit" name="submit" id="submit" value="Submit">
</form>


<?php
if (isset($_POST["submit"])) {
  $path = './upload/';
  $maxFileSize = 1 * (1024 * 1024 * 20);     // 20Mb
  $allowedExts = array("mp3", "wma", "aif");
  $allowedMimes = array("audio/mp3", "audio/mpeg", "audio/x-ms-wma", "audio/x-aiff");
//  $extension = end(explode(".", $_FILES["file"]["name"])); this generates warning pathinfo doesn't
  $extension = pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION);
  if (($_FILES["file"]["size"] < $maxFileSize) && in_array($_FILES["file"]["type"], $allowedMimes) && in_array($extension, $allowedExts)) {
    if ($_FILES["file"]["error"] > 0) {
      echo "Type: " . $_FILES["file"]["type"] . "<br>";
      echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
    } else {
      echo "Upload: " . $_FILES["file"]["name"] . "<br>";
      echo "Type: " . $_FILES["file"]["type"] . "<br>";
      echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
      echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br>";


      if (file_exists($path . $_FILES["file"]["name"])) {
        echo $_FILES["file"]["name"] . " already exists. ";
      } else {
        move_uploaded_file($_FILES["file"]["tmp_name"], $path . $_FILES["file"]["name"]);
        echo "Stored in: $path" . $_FILES["file"]["name"];
      }
    }
  } else {
    echo "Type: " . $_FILES["file"]["type"] . "<br>";
    echo "Invalid file<br/>";
    echo '<pre>' . print_r($_FILES) . '</pre>';
  }
}
?>
</body>
</html>

Thanks in advance for any ideas.

 

Link to comment
Share on other sites

The discrepancy is in one of three variables. You should just print them all out and see if they match the criteria:

echo $_FILES['file']['size'].'<br/>';
echo $_FILES['file']['type'].'<br/>';
echo $extension.'<br/>';

Put that after line 21

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.