I am trying rename file before uploading them without using array, but the problem which I am facing is that the name of the file is not according to what I am mentioning here is my code
$path = "mande/";
$file_name = $_FILES["file"]["name"];
$file2 = $_FILES['file1']["name"];
$time = date('is'); // Minutes and seconds
$newname = abc . '-' . $time;
$newname2 = 'letter' . 'abc' . '-' . $time;
$ext = strrchr($file_name, ".");
$filename = $newname . $ext;
$filename2 = 'letter' . $newname . $ext;
$path = $path . $newname . $ext;
$path2 = $path . $newname2 . $ext;
After using insert query i am trying to move this two by using these statements
move_uploaded_file($_FILES["file"]["tmp_name"], $path);
move_uploaded_file($_FILES["file1"]["tmp_name"], $path2);
First file uploaded gets the exact name as per my need but the second one is having some issue, For example First File name: abc-1234.pdf Second File name: abc-1234.pdfletterabc-1234.pdf INSTEAD OF letterabc-1234.pdf
There are 2 problems:
1) Your path gets mixed up as you are using the same variable again and again. Make your path $storage_path and use that as your base path
2) change $filename2 = 'letter' . $newname . $ext; to $filename2 = 'letter' . $newname2 . $ext;
$storage_path = "mande/"; // FIRST PROBLEM WAS HERE
$file_name = $_FILES["file"]["name"];
$file2 = $_FILES['file1']["name"];
$time = date('is'); // Minutes and seconds
$newname = abc . '-' . $time;
$newname2 = 'letter' . 'abc' . '-' . $time;
$ext = strrchr($file_name, ".");
$filename = $newname . $ext;
$filename2 = 'letter' . $newname2 . $ext; // SECOND PROBLEM WAS HERE
$path = $storage_path . $newname . $ext; // FIRST PROBLEM WAS HERE
$path2 = $storage_path . $newname2 . $ext; // FIRST PROBLEM WAS HERE
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With