TinyPortal

Development => Support => Topic started by: captjlucpicard on July 24, 2008, 10:10:18 AM

Title: PHP Help
Post by: captjlucpicard on July 24, 2008, 10:10:18 AM
I know this might not be the best place to ask, but everyone here seems pretty knowledgeable, so here it goes..

I'm looking to find out how to rename uploaded image files, into "img_1" "img_2" and so on.

Here is my code:

Quote
<?php
$target_path = "uploads/";

if(getimagesize($_FILES['uploadedfile']['tmp_name'])) {




$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    echo "Upload successful. The link to your image is: http://google.com/" .$target_path . "
" ."
". "Signature code: <FONT size=4>Image";
} else{
    echo "There was an error uploading the file, please try again!";
   }

} else {
  die("You may only upload image files!");
}
?>

Currently, when the file is uploaded, it goes the user the link without the filename change. For example: "http://www.google.com/imagecool.jpg" I want this to change to "http://www.google.com/img_1.jpg"
Title: Re: PHP Help
Post by: Ken. on July 24, 2008, 10:41:09 AM
captjlucpicard, most of our code specialists are away for the next few days so you may have to wait a bit before you get an answer.
Title: Re: PHP Help
Post by: IchBin on July 24, 2008, 03:16:25 PM
I don't think the the move_uploade_file function works like that. You will probably have to provide some sort of input box to supply a new file name, and use the rename() function. Just my $.02 anyway. :)