Skip to content
Advertisement

PHP – file_get_contents(): Filename cannot be empty

Can someone help me to handle this error? I don’t know what method or way to get rid of this error. Im new to php and starting to learn it. Can someone give me ideas?

here is the error : enter image description here

here is my php code.

JavaScript

Advertisement

Answer

Why are you adding slahes to your (temporary) filename?

your line 30:

JavaScript

So to remove the error warning:

JavaScript
  • There is a LOT of other things you can / should do with this code but I can’t go over it in too much detail with you, but basically you should check that $_FILES['image']['error'] == 0 to ensure that code only runs if the file has been successfully uploaded.

  • Replace

    JavaScript

With an error check:

JavaScript

Which will mean that only an OK uploaded file will then run the IF statement contents

  • Stop adding slashes, it’s not needed.

  • Use prepared statements for your SQL queries.

  • Move_uploaded_file should in a perfect world be given an absolute path rather than a relative path.

  • Do you realise that you’re file_get_contents is getting the data in a file, not a referece but the actual binary file data. This looks like it’s not what you need to be doing at this stage. Your $image value isn’t clearly used in the code you provide and as rightly pointed out by apokryfos, you’re actually adding slashes to the retrieved filedata of the image. This is going to simply make your $image a garbled mess.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement