Take the 2-minute tour ×

I don't mess with PHP alot, but I don't see what's wrong with this. I had this same exact code working about 15 minutes ago, but now it just stopped working. I didn't change anything, so I'm a little confused.

Anyways, It's a form and you are supposed to submit a screenshot, here's the code for my form,

<form method="post"
<label for="file">Screenshot of them agreeing to terms:</label>

I don't think anything is wrong with that. Here's the PHP that handles all this (I think/hope)

 if(isset ($_POST['loanee'])) {
    $name = md5_file(sys_get_temp_dir() . $_FILES['tmp_name']);
      move_uploaded_file(sys_get_temp_dir() . $_FILES["files"]['tmp_name'], "public_html/mc/images/{$name}.jpeg");

I am not getting anything echoed to me, and no errors are showing up in the error log, so what's wrong?

Thanks for any help.

Loanee is not the problem, as my sql database IS being updated after the picture is "uploaded", I didn't put the whole form, as some of it has some information I don't think is necessary, the form is working fine as I said before, sorry to everyone that keeps telling me that loanee isn't set in the form, it is.

share|improve this question
Where is loanee???? –  xdazz Oct 14 '11 at 7:16
You should give the uploaded file the proper file extension. .jpeg is not correct for all three of them. –  Roland Illig Oct 14 '11 at 7:19
where is the element that has name loanee in your form on which you are applying the isset($_POST['loanee']) –  punit Oct 14 '11 at 7:19
I think you have another typo in the last line of code. You access the _FILES variable in two different ways. –  Roland Illig Oct 14 '11 at 7:21

3 Answers 3

up vote 1 down vote accepted

You don't have to use sys_get_temp_dir(). The $_FILES["files"]['tmp_name'] will already point to the temp dir.

So change your code to something like this:

$name = md5_file($_FILES["file"]['tmp_name']);
move_uploaded_file($_FILES["file"]['tmp_name'], "public_html/mc/images/{$name}.jpeg");

Edit: Oh, and you should use is_uploaded_file to check whether or not a file has been uploaded.

share|improve this answer
I get an error saying Filename cannot be empty on line 46, this is line 46 $name = md5_file($_FILES['tmp_name']); –  Austin Oct 14 '11 at 7:27
@Austin Oh yeah, you have to reference it the same way as with move_uploaded_file.. eg. $_FILES['files']['tmp_name']. Will fix that in my answer –  bummzack Oct 14 '11 at 7:29
Fixed it now.. the key for the $_FILES array should be the same as your form-input field. So in your case it's "file" –  bummzack Oct 14 '11 at 7:30
Now I get these two errors, Warning: move_uploaded_file(public_html/mc/images/7485273b2147c49e10271596d2b1d764.jpeg) [function.move-uploaded-file]: failed to open stream: No such file or directory in /public_html/mc/CreateLoan.php on line 46 Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpWUwCoI' to 'public_html/mc/images/7485273b2147c49e10271596d2b1d764.jpeg' in /public_html/mc/CreateLoan.php on line 46 –  Austin Oct 14 '11 at 7:32
Your path is wrong. If your script resides in public_html/mc, your path should be relative to that (eg. just images/{$name}.jpeg), or use absolute paths instead. Also make sure the directory is writable for php scripts (usually by making it writable by the "web-process" user). –  bummzack Oct 14 '11 at 7:35

I don't see where $_POST['loanee'] gets set, but it needs to be set. Otherwise the interesting code is just skipped.

share|improve this answer
Sorry, It is being set. That part is working correctly (I am updating a sql database after picture is uploaded) Should've said that before. –  Austin Oct 14 '11 at 7:18
Austin, is it part of the same form though? If it is not enclosed under the same form tag, clicking on submit may not give you all the variables you want. –  Edison Oct 14 '11 at 7:23
@Edison Yes it's the same form, thanks for your response. –  Austin Oct 14 '11 at 7:29

At the first line of your php script you check for the loanee variable that supposed comes from the HTML Form, but you don't have any field in your form with that name.

More specific :

if(isset ($_POST['loanee'])) {    // That line does not correspond to any input element into your form

To solve your provlem either remove that statment control or add a new field into your form with that name

share|improve this answer
It's in the form, I just didn't upload the whole form. I updated my first post. Sorry, I just didn't think the whole form would be necessary. –  Austin Oct 14 '11 at 7:23
Try to disable that statement control in order to check if the uploading still working. If working then you can focus on that statement –  Merianos Nikos Oct 14 '11 at 7:24

Your Answer


