Question

I'm having strange issues when uploading to the server via PHP.

I get the type of the file (working properly, it shows them via echo)

$file = $_FILES['file'];
$typeFile = end(explode(".", $file['name']));

Then I make some comparasions to let them upload it or not, here are the fille types allowed

if($file['size'] <= 52428800) { //50MB, and my file is about 2,5MB
    if($fileType == "nlpack" || $fileType == "nl2pkg" || $fileType == "nlpark") {
        $id = add_to_db($file['name']); //Adding to database the name, this will return an id, it works
        if($id) {
            mkdir("uploads/".$id); //create a folder where to add the file, working fine!
            if(move_uploaded_file($file['tmp_name']), ".uploads/".$id."/".$file['name']) {
                echo "file uploaded correctly";
            }
            else {
                echo "has been an error"; //it enters here, while the other file types enters in the if()
            }
        }
        else {
            echo "Has been an error";
        }
    } else {
        //alert an error
    }
}

The thing is, that "nlpack" file type doesn't uploads, and it enters the if() because I checked it with echos, while the other two are uploaded without problem.

I also check the file size, but that's running fine.

Any ideas of what is going on?

Thanks in advance

Was it helpful?

Solution

Make sure the filesize isn't exceeding the settings in your php.ini or the file will just fail to upload.

upload_max_filesize integer
The maximum size of an uploaded file.

When an integer is used, the value is measured in bytes. Shorthand notation, as described in this FAQ, may also be used.

AND if muliple:

max_file_uploads integer
The maximum number of files allowed to be uploaded simultaneously. Starting with PHP 5.3.4, upload fields left blank on submission do not count towards this limit.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top