-1

Let's say I want to upload a csv file to PHP. I noticed in Chrome if I select, for example, "test.csv" in the file selection box, if I rename the file locally to "test1.csv", then upon submitting the form to PHP, I see an error page:

ERR_FILE_NOT_FOUND

I want to catch this error and show a friendly error message instead.

Ultimater
  • 4,647
  • 2
  • 29
  • 43
naing linhtut
  • 791
  • 1
  • 6
  • 9
  • Please explain what you mean by "First I select some csv file to upload and then before upload I have changed rename of that file." Are you renaming the file you selected in the HTML form before submitting the form to PHP? Please show us some code so we have something to work with. Perhaps we can explain what you're doing wrong. – Ultimater Aug 28 '15 at 02:24
  • I means first I select one csv file name as "test.csv" from my desktop to upload but i didn't click upload button. and then I have changed rename of that select csv file as "test1.csv" in my desktop and then I click upload button and found this message "ERR_FILE_NOT_FOUND" in google chrome. I want to be that I want to show this message "your file is not exists where your selected". – naing linhtut Aug 28 '15 at 02:34
  • So in other words you're intentionally causing this error, for testing purposes, by renaming the file on your desktop, to make your application more stable for rare situation, and want to write some PHP code which is able to test for this error in order to make a pretty error page to notify the user that they tried to upload a non-existent file? Are you using jQuery to handle the upload, or are you using plain HTML? – Ultimater Aug 28 '15 at 03:02
  • yes i'm using plain HTML. – naing linhtut Aug 28 '15 at 04:04

1 Answers1

0

The issue you described has nothing to do with PHP or jQuery. I have isolated the issue you have described down to:

<form action="http://www.google.com" method="POST" enctype="multipart/form-data">
<p>Select a file, for example z.txt, then before clicking submit,
rename the file locally so the file picked is invalid, such as zz.txt,
then submit to get an error in chrome.</p>
<input type="file" name="myFile">
<input type="submit" />
</form>

Yes, it doesn't even matter where the form sends to. Chrome will error if the file doesn't exist before it tries to send. Firefox, however, will submit the form as usual. This is an issue with chrome. You can, however, adjust chrome to hide network messages:
Suppress "Failed to load resource: net::ERR_FILE_NOT_FOUND" in Chrome Packaged App

Community
  • 1
  • 1
Ultimater
  • 4,647
  • 2
  • 29
  • 43