ok, i made a thing so that i can upload files to my server through a page without using ftp or anything. but when i upload a picture that already exists it doesn't overwrite it. how can i make a little checkbox that when checked will overwrite the file. if it makes any difference here is my script right now.
<?php
//check for file upload
if(isset($UploadedFile))
{
copy($UploadedFile, "/home/structur/public_html/eternalmind/images/$UploadedFile_name");
print("Local File: $UploadedFile <br>\n");
print("Name: $UploadedFile_name <br>\n");
print("Size: $UploadedFile_size <br>\n");
print("Type: $UploadedFile_type <br>\n");
print("URL: <a href=http://www.htmlforums.com/archive/index.php/\"http://structuralstudios.com/eternalmind/images/$UploadedFile_name\" target=\"_blank\">http://structuralstudios.com/eternalmind/images/$UploadedFile_name</a><br>\n");
print("<img src=http://www.htmlforums.com/archive/index.php/\"/eternalmind/images/$UploadedFile_name\"> <br>\n");
unlink($UploadedFile);
}
?>
<form enctype="multipart/form-data" action="<? $PHP_SELF ?>" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="1000000">
<input name="UploadedFile" type="file">
<br><br>
<input type="submit" value="Upload The Files">the only reason it won't overwrite is because the file names are different.
but, by default it should overwrite. you can't tell it not to if the file name is the same.ok then, how do i make it so i can choose if i want to overwrite it or not?well you could set a checkbox on the form and if this is checked upon submitting then you can just add a variable to the image's name. so say you uploaded a image and the name was
image.jpg. if that was checked to NOT overwirte it then you could get the name and take the extensioon off and then add a 1 or another number to the name. or you could add a date to it.
so image.jpg would be image_1.jpg or image_20020324.jpg
many way to do it.
<?php
//check for file upload
if(isset($UploadedFile))
{
copy($UploadedFile, "/home/structur/public_html/eternalmind/images/$UploadedFile_name");
print("Local File: $UploadedFile <br>\n");
print("Name: $UploadedFile_name <br>\n");
print("Size: $UploadedFile_size <br>\n");
print("Type: $UploadedFile_type <br>\n");
print("URL: <a href=http://www.htmlforums.com/archive/index.php/\"http://structuralstudios.com/eternalmind/images/$UploadedFile_name\" target=\"_blank\">http://structuralstudios.com/eternalmind/images/$UploadedFile_name</a><br>\n");
print("<img src=http://www.htmlforums.com/archive/index.php/\"/eternalmind/images/$UploadedFile_name\"> <br>\n");
unlink($UploadedFile);
}
?>
<form enctype="multipart/form-data" action="<? $PHP_SELF ?>" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="1000000">
<input name="UploadedFile" type="file">
<br><br>
<input type="submit" value="Upload The Files">the only reason it won't overwrite is because the file names are different.
but, by default it should overwrite. you can't tell it not to if the file name is the same.ok then, how do i make it so i can choose if i want to overwrite it or not?well you could set a checkbox on the form and if this is checked upon submitting then you can just add a variable to the image's name. so say you uploaded a image and the name was
image.jpg. if that was checked to NOT overwirte it then you could get the name and take the extensioon off and then add a 1 or another number to the name. or you could add a date to it.
so image.jpg would be image_1.jpg or image_20020324.jpg
many way to do it.