michaelnaeseth
New member
...upload-1.ext - upload-2.ext )? The PHP script I am using changes the name of the file to the last name of the uploader. If the uploader chooses to upload 4 files, how do I get the php script to recognize that and stick an ascending number on the back of the filename?
Here is my current php script:
<?php
$target = "uploads/";
$target = $target . basename( $_FILES['uploaded']['name']) ;
$ok=1;
$explode = explode('.', $_FILES['uploaded']['name']);
$extension = array_pop($explode);
$newname = $_POST['lastname'].'.'.$extension;
if ($uploaded_size > 1000000)
{
echo "Your file is too large. Please re-size your image and retry. (Max file size = 1 MB)<br>";
$ok=0;
}
if ($uploaded_type =="text/php")
{
echo "No PHP files<br>";
$ok=0;
}
if ($uploaded_type =="text/html")
{
echo "No HTML files<br>";
$ok=0;
}
if ($uploaded_type =="text/htm")
{
echo "No HTM files<br>";
$ok=0;
}
if ($uploaded_type =="text/xml")
{
echo "No XML files<br>";
$ok=0;
}
if ($ok==0)
{
Echo "An error occured during the upload, your file was not uploaded";
}
else
{
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], 'uploads/'.$newname))
{
echo "The file ". basename( $_FILES['uploaded']['name']). " has been uploaded";
}
else
{
echo "Sorry, there was a problem uploading your file.";
}
}
?>
Here is my current php script:
<?php
$target = "uploads/";
$target = $target . basename( $_FILES['uploaded']['name']) ;
$ok=1;
$explode = explode('.', $_FILES['uploaded']['name']);
$extension = array_pop($explode);
$newname = $_POST['lastname'].'.'.$extension;
if ($uploaded_size > 1000000)
{
echo "Your file is too large. Please re-size your image and retry. (Max file size = 1 MB)<br>";
$ok=0;
}
if ($uploaded_type =="text/php")
{
echo "No PHP files<br>";
$ok=0;
}
if ($uploaded_type =="text/html")
{
echo "No HTML files<br>";
$ok=0;
}
if ($uploaded_type =="text/htm")
{
echo "No HTM files<br>";
$ok=0;
}
if ($uploaded_type =="text/xml")
{
echo "No XML files<br>";
$ok=0;
}
if ($ok==0)
{
Echo "An error occured during the upload, your file was not uploaded";
}
else
{
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], 'uploads/'.$newname))
{
echo "The file ". basename( $_FILES['uploaded']['name']). " has been uploaded";
}
else
{
echo "Sorry, there was a problem uploading your file.";
}
}
?>