Waiting for localhost after uploading one file

whenever i upload a file my wamp gets stuck in waiting for localhost. and the only way to fix that is to restart phpstorm which is well… not a good fix i want a permanent fix my upload code is really small so idk whats the problem :confused:

Post the upload code.

1 Like

it’s small… only validation but sure

<?php
    $extension = pathinfo($_FILES['uploadvideo']['name']);
    if(!$_FILES['uploadvideo']['tmp_name']){
$errors[]="Please choose a video";
    }
    if($_FILES['uploadvideo']['tmp_name']){
// wanted to do validation here but the error is preventing me :slight_smile: 
            }

 } ?>

What error? You didn’t mention an error before.

I can’t see why that makes the server stall, but it’s not really doing anything. Does it start to run, if you add

echo "starting";

just before the line that starts $extension =, does it display that?

How big is the file you’re testing it with?

its less than 1mb i doubt that size is the problem. by error i mean the waiting for localhost and it doesn’t display echo “starting”; i’m using bootstrap 4 modal to handle uploading. but the $errors array gets displayed when user doesn’t put any file and clicks the submit button…

File extensions shouldn’t be relied on. Anyone can create a file in .txt, write malicious code, and then rename the file extension to say .jpg or even .mp4.


Edited to correct myself.

i know that but i can’t do anything. once a file is uploaded i have to restart phpstorm to get it to work (upload more files)
i had $extension ready but i can’t do anything with it :confused:

What I meant was “shouldn’t”, not “should”. I hate using mobile phones as the auto correct is really stupid. You shouldn’t rely on file extensions like I said.

i know that but what should i rely on then? someone told me that i can put chmod 750 or 0644 after the file is saved. just in case it was .anyextension.php.

Not that it solves your problem but

if(!$_FILES['uploadvideo']['tmp_name']){
...
}
if($_FILES['uploadvideo']['tmp_name']){
...
}

isn’t very good coding. That’s what the else clause is for…

I noticed that. I changed it right after this post.

1 Like

comn guys… nobody knows how to fix this? or atleast explain why?

WAMPP and XAMPP has a tendency to be really slow. I suggest installing Ubutnu and working with PHP there. The upload time for Windows is normal since Windows takes way longer to execute a task. Your upload script however has legacy code problems so you should try fixing those before you get too far a head of yourself.

that’s not really a “fix” but i will go wit it.
is it okay if i install ubutnu on virtual box?

Go for it. I am not going to force you like some of the members on here. Just remember to fix your upload script since from the looks of it, you might be using legacy codes.

thanks, but how is that legacy code? soits okay if i use ubutnu on virtualbox? it wont affect performance whatsoever?

I suspect the problem isn’t what your development set-up is, but how it is configured.

On my Windows 10 I often use Apache as a service that ties in with PHP, and various databases.

I also have virtual machines, including Ubuntu.

I have no details to prove it, but I am sure there are at least some differences between running PHP in Ubuntu in a VM in Windows and running PHP directly in Ubuntu

In any case, setting up VMs can get gnarly and indeed, even configuring any development environment can be tricky.

I suggest you forego pursuing a VM at least for now.
You may be able to study your conf and ini files and spot the cause of the problem you are are having. But be warned, these files are not good things to edit based on guesses.

I do suggest you make sure you have error reporting and display errors on in your dev env.
Error messages such “undefined”, “size”, “time” etc. can help greatly in pinning down what the problem is.

1 Like

If you’re using stuff that isn’t just pure HTML and PHP, it might be worth mentioning that at the start. I have no experience with that so wouldn’t even have tried to suggest things had I known you were using anything other than the PHP code you posted.

1 Like

finfo() is one option that does a bit more than just look at the file extension and therefore is less likely to allow files through that try to misidentify themselves.

for some file types you can also make use of functions that only work with those types eg. exif_imagetype() for images.

1 Like

:open_mouth:

Just looked at mime_content_type again and it seems that the PHP devs have removed the deprecated message for mime_content_type. It seems that it’s being supported again or am I wrong?

:smiley: Yes I am right.