0

I created a website that allow the uploading of files (songs) and everything was working fine but all of a sudden files stopped uploading in my own device but when I used another person's device the file uploaded successfully. It seems when ever a user uploads some files (maybe 10 or 5 or even 4) the upload script will stop working for that particular device irrespective of the browser. I just received a report from a user telling me the same experience. How do I fix this?

$maxsize     = 12345678; 
$target_dir  = "songs/";
$target_file = mysqli_real_escape_string($con,$target_dir . $_FILES["file1"]["name"]);
$fileName    = $_FILES["file1"]["name"]; // The file name
$fileTmpLoc  = $_FILES["file1"]["tmp_name"]; // File in the PHP tmp folder
$fileType    = $_FILES["file1"]["type"]; // The type of file it is
$fileErrorMsg= $_FILES["file1"]["error"]; // 0 for false... and 1 for true

// Select file type
$audioFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));

// Valid file extensions
$extensions_arr = array("mp3","wma","wav","ogg");

// Check extension
if( in_array($audioFileType,$extensions_arr) ){

    // Check file size
    if(($_FILES['file1']['size'] >= $maxsize) || ($_FILES["file1"]["size"] == 0)) {
        echo "<h6>Your audio file is too large, please compress your file and try again. </h6>";
    }else{
        $sql = mysqli_query($con,"SELECT * FROM songs WHERE name = '$fileName' AND location='$target_file'");
        $num = mysqli_num_rows($sql);
        if($num == 1){
            echo "<h6 style='color:red'>Failed to upload file. Possible duplicate<br/>Duplicate error</h6>";
        }else{
            // Upload
            if(move_uploaded_file($fileTmpLoc,$target_file)){
                // Insert record
                $query = "INSERT INTO songs (name,location,text,username) 
                VALUES('".$fileName."','".$target_file."','".$text."' ,'".$_SESSION["username"]."')";
                mysqli_query($con,$query);
                echo "<br />";
                echo "<h4>".$fileName." has been uploaded successfully</h4>";
                echo "<div class='loader'></div><h6 style='color:green'>Kindly click on the home icon and search your audio 
      file to ensure it has been uploaded successfully...</h6>";
            }
        }
    }
}else{
    echo "<h6></h6>";
}
Don't Panic
  • 13,965
  • 5
  • 32
  • 51
  • No error messages? And why are you just exposing "
    " without a message? What do you mean with ".. stops working"?
    – thmspl Dec 06 '19 at 08:28
  • `will stop working` - that doesn't tell us much, what does it mean, exactly? Some errors? What does your browser do, what does the devtools network tab show happened with the request? How about your webserver and PHP logs? – Don't Panic Dec 06 '19 at 08:29
  • 1
    By the way, your code is [open to SQL injection](https://xkcd.com/327/). Stop everything, and fix it - [use PDO and parameters](https://stackoverflow.com/a/60496/6089612). – Don't Panic Dec 06 '19 at 08:31
  • @thmspl no error mesage is showing at all, I don't know if it has something to do with my file upload progress bar script. But if it has something to do with the file upload progress bar script the files shouldn't have even uploaded at all but all what the script does is after a user must have been uploading files for a while it will just stop uploading files in that user device but if the user uses another device the file will upload succesfuly. M stuck. –  Dec 06 '19 at 09:11
  • @thmspl Concerning the
    tag I noticed when I add a text on it when ever I open the upload file page the text will appear at the top of the page so I had to leave it blank
    –  Dec 06 '19 at 09:13
  • @Don't Panic the script doesn't show any error at all I've tried all my possible best to see if I can get errors from it but it doesn't show any. My php.ini error_reporting is ON –  Dec 06 '19 at 09:15
  • I suggested several other things to check out: `what does the devtools network tab show happened with the request? How about your webserver and PHP logs?` – Don't Panic Dec 06 '19 at 09:17
  • I contacted my webserver and they said nothing is wrong with my PHP config that I should check my script –  Dec 06 '19 at 10:06

0 Answers0