0
votes

I need to do a file upload for videos. i am able to upload the videos with php but i need a way to display the file uploading progress with php and when its 100% uploaded i should display the success message.

File uploading is currently done with ajax.

The issue is, i tried with is_uploaded_file method but this code runs before file is being upload and always it returns false. http://us1.php.net/is_uploaded_file

Should i used any background process ?

<?php

if (is_uploaded_file($_FILES['userfile']['tmp_name'])) {
   echo "File ". $_FILES['userfile']['name'] ." uploaded successfully.\n";
   echo "Displaying contents\n";
   readfile($_FILES['userfile']['tmp_name']);
} else {
   echo "Possible file upload attack: ";
   echo "filename '". $_FILES['userfile']['tmp_name'] . "'.";
}

?>
1
"Should i used any background process ?" - If you like the fancy stuff, sure why not; if it's to impress your client(s). Other than that, the fancy stuff sometimes leaves room for injection.Funk Forty Niner
@Fred-ii- can you pls tell me how to use a background process with php ?dev1234

1 Answers

1
votes

is_uploaded_file() function will check that file which you are is upload-able or not.

Instead of that function use move_uploaded_file() function.

Refer: http://php.net/manual/en/function.move-uploaded-file.php

  if (is_uploaded_file($_FILES['userfile']['tmp_name']) && move_uploaded_file($_FILES['userfile']['tmp_name'], "put here target directory path")) {
    echo "File ". $_FILES['userfile']['name'] ." uploaded successfully.\n";
    echo "Displaying contents\n";
    readfile($_FILES['userfile']['tmp_name']);
  } else {
    echo "Possible file upload attack: ";
    echo "filename '". $_FILES['userfile']['tmp_name'] . "'.";
  }