Image not writing to server

I have a form which lets user insert data into the DB (this bit works). The script is also meant to upload the image to the server but it isn’t working. Here’s the script…

<?php 

//This is the directory where images will be saved 

$target = "images/"; $target = $target . basename( $_FILES['photo']['name']); 

//This gets all the other information from the form 

$title=$_POST['name']; $description=$_POST['description']; $step1=$_POST['step1']; $image1=($_FILES['photo']['name']); 

$con = mysql_connect("xxxxxxxxxxxx","xxxxxxxxxxx","xxxxxxxxxx");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("xxxxxxxxxx", $con);

//Writes the information to the database 

$sql="INSERT INTO 

gallery (title, description, step1, image1) 

VALUES ('$title','$description', '$step1', '$image1')"; 





//Writes the photo to the server 

if(move_uploaded_file($_FILES['photo']['tmp_name'], $target)) { 
	
//Tells you if its all ok 

echo "The file ". basename( $_FILES['uploadedfile']['name']). 

" has been uploaded, and your information has been added to the directory"; } 

else { 
	
//Gives and error if its not 

echo "Sorry, there was a problem uploading your file."; } 


//DISCONNECT FROM DATABASE
mysql_close($con);

?> 

I get this success message in the browser…

The file has been uploaded, and your information has been added to the directory

The message doesn’t echo the file no though and I think it should do. The is a directory in the correct location with permissions.

Can anyone help me with this please?

thanks very much :slight_smile:

Change

$_FILES[‘uploadedfile’][‘name’]

to

$_FILES[‘photo’][‘name’]

and your success message will work.

It may not be show up with FTP if the images are owned by the apache user. You could try http://www.php.net/manual/en/function.chown.php

script still doesn’t echo file name in success message but it is writing them to the server. They weren’t showing up in filezilla!!