problem getting file name

Hey guys, I have a form where my client can update his website news.

The form has this fields:

- title field
- current photo field
- new photo file field
- A checkbox, if he checks, he can upload a new photo for this post
- description field

Everything works fine, expect that I can't get the filename of "foto2". I don't know why it's not working.

any ideas?

<?php
     if(@$_GET['acao'] == "atualizar"){
		 $titulo = $_POST['titulo'];
		 $foto = $_POST['foto'];
		 $texto = $_POST['texto'];
		 $alterafoto = $_POST['alterar'];
		 $uploaddir = 'uploads/';
		 $uploadfile = $uploaddir . random_number(5,'abcd1234') . "_" . basename($_FILES['foto2']['name']);
		 
			 if($alterafoto=="sim"){//change photo?
			 	 move_uploaded_file($_FILES['foto2']['tmp_name'], $uploadfile);
				 $sqlfoto="UPDATE $tbl_name SET titulo='$titulo', foto='$uploadfile', texto='$texto' WHERE id='$id'";
				 mysql_query($sqlfoto);
					 if(mysql_affected_rows() > 0 ){
						echo "<span class=\"sucesso\">Registro Atualizado!</a>";
						exit;
						}else{
						echo "<span class=\"erro\">Ocorreu um erro, tente novamente!</a>";
						exit;
						}	
			 
			 }else{//just update the text
			 
		     //$id = $_GET['id'];
				 $sql2="UPDATE $tbl_name SET titulo='$titulo', foto='$foto', texto='$texto' WHERE id='$id'";
				 mysql_query($sql2);
					if(mysql_affected_rows() > 0 ){
					echo "<span class=\"sucesso\">Registro Atualizado!</a>";
					exit;
					}else{
					echo "<span class=\"erro\">Ocorreu um erro, tente novamente!</a>";
					exit;
					}			 
			 
			 }	 		 
		
	 }
	 ?>

Open in new window

fackzAsked:
Who is Participating?
 
fackzConnect With a Mentor Author Commented:
just removed the file field from the form, put it again, changed the name and it worked
0
 
EMB01Connect With a Mentor Commented:
I believe this is because of your random_number function.

See: http://us3.php.net/rand
0
 
fackzAuthor Commented:
I'm getting in the database the uncompleted names...like:

19df9_

And this is just happening on this form...I have a lot of similar forms working fine with this function...

Whats missing here is the filename, like photo.jpg, so I should have:

uploads/19df9_photo.jpg
0
 
EMB01Connect With a Mentor Commented:
Try echo'ing a var_dump of the $_FILES array and let me know what output you get.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.