I need help with PHP file upload


And how does that code relate to the file upload code you posted? Does it come before it, after it, somewhere around it?

I’m still confused that you’re trying to access $_POST['uploadfile'] to store in your database, when it should be one of the $_FILES array elements that you use, or maybe even $target_file from your file upload code. Surely you still get an “undefined index” error for that?

Or have you separated things out to an entirely separate form for the CV upload? I don’t “get” how this all links up.

1 Like

Looks like it’s coming before the database insert. The include has the filename. I think the main problem is that the OP is trying to create 2 separate instances of the form. I don’t think this is going to work because again, the logic behind it is flawed.

@Sora I’ll give you a hint to your problem.

Check to make sure the file is actually uploaded. Once it’s uploaded, reference the ['name'] and just insert that. Don’t create these random logics that will never work.

1 Like

I love you man :sob::sob::sob::sob::sob::sob::sob:

in the query I did this:

$uploadCV = $_FILES['uploadCV']['name'];

and now I see the files being uploaded, AND being displayed in the DB :heart:
plus all the error are gone

1 Like
if (file_exists($target_file)) {
    echo "Sorry, file already exists.";
    $uploadOk = 0;

So this a job application, so chances are multiple people will upload cv.pdf.
Once one has done that no other person can upload a file with the same name anymore?
They’d have to guess which file does not exist on your system yet?


Nice catch there. Hashing the new filename should be the next step. I would actually create another column to store the original filename and then the hashed filename. Good for reference.


Yes, I didn’t mention the second task of this code. is to Auto rename the uploaded file to user’s Email OR full name


So I am only allowed to apply once?


No, you get to apply more than once. Since that is happening, I will consider your code so the person may upload the same file in multi positions or same position multiple times.

i thank you for your code!


Lol, no. This is not a coding service.

I’d be happy to review your code or help you along once you’ve tried something yourself, but I’m not going to write the entire thing on request.

closed #30

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.