This code lets the user upload a jpeg to a directory called "gallery_001_images". Works fine except I want it to change the name of the jpeg (whatever it's original file name is) to "1.jpg" and replace "1.jpg" if there's already one there. I've been trying all day to make this work to no avail. Please could somebody correct this??? (Please don't tell me what I need to do, please show me with the code in place as I'm really stoopid with PHP!) Oh, and I know the "rename line is wrong... it was just a wild guess.
<?php
$target_path = "uploads/";
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
$rename("name", "1.jpg");
$target_path = "gallery_001_images/";
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['uploadedfile']['name']).
" has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
}
?>
<?php
$target_path = "uploads/";
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
$rename("name", "1.jpg");
$target_path = "gallery_001_images/";
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['uploadedfile']['name']).
" has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
}
?>