Forum Moderators: coopster

Message Too Old, No Replies

How to change name of uploaded image file?

         

bellasiena

3:12 am on Nov 23, 2004 (gmt 0)



Hello,

I'm using the following script to upload an image to my server. It uses the script: fileupload-class.php:

<snipped url>

It's working fine except it uses the uploaded file name when placing the file into my web server folder. I would like to change the filename before it is copied to the folder.

I've tried everything to figure out how this is done. I've had no luck. Would someone be able to tell me where in the script I can change the name of the file before it is copied into the folder on my server? (i.e., agent_image_001.gif)

Any help would be greatly appreciated. Gary

-----------------------

<?php
require("fileupload-class.php");
$path = "agent_images/";
$upload_file_name = "userfile";
$acceptable_file_types = "image/gifs";
$default_extension = "gif";
$mode = 1;
if (isset($_REQUEST['submitted'])) {
$my_uploader = new uploader($_POST['en']);
$my_uploader->max_filesize(20000); // 20 kb
$my_uploader->max_image_size(200, 150); // max_image_size($width, $height)
if ($my_uploader->upload($upload_file_name, $acceptable_file_types, $default_extension)) {
$my_uploader->save_file($path, $mode);
}

// if attempted to overwrite existing file, take a look in the folder to see what's there
if ($my_uploader->error) {
$web='<A HREF="http://www.example.com.com/agent_images/look.php" TARGET="_blank"';
$er="<br><br>";
$er1="<br><br>";
$er2=$er.$er1;
echo $my_uploader->error . "<br>\n\n$er2\n";
}
else {
print "<font size=\"-1\" face=\"Verdana, Arial, Helvetica, sans-serif\">" . "[ " . ($my_uploader->file['name'] . " ] has been uploaded successfully.<br><br></font>");

if(stristr($my_uploader->file['type'], "image")) {
echo "<img src=\"" . $path . $my_uploader->file['name'] . "\"border=\"0\" alt=\"\"><BR>";
}
else {
$fp = fopen($path . $my_uploader->file['name'], "r");
while(!feof($fp)) {
$line = fgets($fp, 255);
echo $line;
}
if ($fp) { fclose($fp); }
}
}
}
?>

[edited by: coopster at 2:44 pm (utc) on Nov. 23, 2004]
[edit reason] removed url per TOS [webmasterworld.com] [/edit]

Birdman

2:51 pm on Nov 23, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It may not even be built into the class. You'll probably need to modify the function, save_file(), in the class to accept one more parameter(new name).

Welcome to WW!