I have a script that I am customizing. I have it how I want it except that I need it to do:
1) During the upload process it needs to change the filename to picture_01.jpg where the number is decided based on the number of images in the folder.
Ex: i upload a file called 8756hy.jpg I need the program to call the file picture_01.jpg
Please help!
<?php
$site_name = $SERVER['HTTP_HOST'];
$url_dir = "http://".$SERVER['HTTP_HOST'].dirname($SERVER['PHP_SELF']);
$url_this = "http://".$SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
$upload_dir = "images/";
$upload_url = $url_dir."/images/";
$message ="";
//create upload_files directory if not exist
//If it does not work, create on your own and change permission.
if (!is_dir("images")) {
die ("upload_files directory doesn't exist");
}
if (@$_FILES['userfile']) {
$message = do_upload($upload_dir, $upload_url);
}
else {
$message = "Invalid File Specified.";
}
//print $message;
function do_upload($upload_dir, $upload_url) {
$temp_name = $_FILES['userfile']['tmp_name'];
$file_name = $_FILES['userfile']['name'];
$file_type = $_FILES['userfile']['type'];
$file_size = $_FILES['userfile']['size'];
$result = $_FILES['userfile']['error'];
$file_url = $upload_url.$file_name;
$file_path = $upload_dir.$file_name;
$thisfilename = $file_name;
$filesep = split ('[.]', $thisfilename);
$extension = $filesep[1];
//File Name Check
if ( $file_name =="") {
$message = "Invalid File Name Specified";
return $message;
}
//File Size Check
else if ( $file_size > 2000000) {
$message = "The file size is over 500K.";
return $message;
}
//File Type Check
else if ( $file_type == "text/plain" ) {
$message = "Sorry, You cannot upload any script file" ;
return $message;
}
if ( $extension == "jpg" ) {
$result = move_uploaded_file($temp_name, $file_path);
}
if ( $extension == "JPG" ) {
$result = move_uploaded_file($temp_name, $file_path);
}
$message = ($result)?"File url <a href=$file_url>$file_url</a>" :
"Something is wrong with uploading a file.";
return $message;
}
print("<HTML>");
@$postuser = $POST['postuser'];
@$postpass = $POST['postpass'];
@$postlogout = $_POST['logout'];
print("<FORM ACTION='./admin.php' METHOD='POST'>");
print("<INPUT TYPE='HIDDEN' NAME='postuser' VALUE=$postuser>");
print("<INPUT TYPE='HIDDEN' NAME='postpass' VALUE=$postpass>");
print("<INPUT TYPE='SUBMIT' VALUE='Image Uploaded. Continue.'");
print("</FORM>");
print("<FONT FACE=VERDANA SIZE=1 COLOR=#FFFFFF>");
include("./fileviewer.php");
print("</FONT>");
?>