Im trying to upload a mp3 file with the size of approximately 6MB. The problem is that I keep getting following output from print_r($file)
Array
(
[name] => a.mp3
[type] =>
[tmp_name] =>
[error] => 1
[size] => 0
)
I guess I have the error code 1, now I've read Can't upload mp3 files on my php script and set my settings to
memory_limit = 99M
max_execution_time = 300
upload_max_filesize = 20M
post_max_size = 24M
Now I cant even upload images anymore because it will throw error 0.
What did I do wrong?
Here is my code
$file = $_FILES['file'];
$id = $_POST['id'];
$title = $_POST['title'];
print_r($file);
$id=htmlspecialchars(strip_tags($id));
$fileName = $_FILES['file']['name'];
$fileTmpName = $_FILES['file']['tmp_name'];
$fileSize = $_FILES['file']['size'];
$fileError = $_FILES['file']['error'];
//$fileType = $_FILES['file']['type'];
$fileExt = explode('.', $fileName);
$fileActualExt = strtolower(end($fileExt));
$allowedImage = array('jpg', 'jpeg', 'png', 'pdf');
$allowedPodcast = array('mp3');
$allowedVideo = array('mp4');
if (in_array($fileActualExt, $allowedPodcast)) {
if ($fileError === 0) {
if ($fileSize < 1000000) {
try {
$conn->beginTransaction();
$fileNameNew = uniqid('', true).".".$fileActualExt;
$fileDestination = '../api/data/object/'. $id . '/image%' .$fileNameNew;
move_uploaded_file($fileTmpName, $fileDestination);
$query = "INSERT INTO media SET type='image', url=:url, id_object=:id_object, title=:title";
$stmt = $conn->prepare($query);
$stmt->bindParam(":url", $fileDestination);
$stmt->bindParam(":id_object", $id);
$stmt->bindParam(":title", $title);
$stmt->execute();
$conn->commit();
echo json_encode(array("message" => "file inserted successfully!"));
} catch (Exception $e) {
$conn->rollBack();
echo json_encode(array("message" => "An error occured!"));
}
} else {
echo json_encode(array("your file was too big"));
}
} else {
echo json_encode(array("message" => "there was an error uploading your file"));
}
}