• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 284
  • Last Modified:

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

0
fackz
Asked:
fackz
  • 2
  • 2
3 Solutions
 
EMB01Commented:
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
 
EMB01Commented:
Try echo'ing a var_dump of the $_FILES array and let me know what output you get.
0
 
fackzAuthor Commented:
just removed the file field from the form, put it again, changed the name and it worked
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now