i am using this code to upload files(images to a folder)
<form action='' method='POST' enctype='multipart/form-data'> <input type='file' name='userFile'><br> <input type='submit' name='upload_btn' value='upload'> </form> <?php $target_Path = "images/"; $target_Path = $target_Path.basename( $_FILES['userFile']['name'] ); move_uploaded_file( $_FILES['userFile']['tmp_name'], $target_Path ); ?>
when the file(image) is saved at the specified path... WHAT if i want to save the file with some desired name....
i have tried replacing THIS
$target_Path = $target_Path.basename( $_FILES['userFile']['name'] );
WITH THIS
$target_Path = $target_Path.basename( "myFile.png" );
BUT it's not working
Typically, you will find the tab or button labeled “Add Files”. You'll then find and select the files either on your computer or on a flash drive, external drive, or memory card. You can click the “Open” button which begins the uploading process.
The most popular way to publish files to the web is by using an FTP (file transfer protocol) program. These programs create a link between your computer and the server that hosts your account, allowing you to copy and paste (or click and drag) your website files to your HostPapa hosting space.
You can try this,
$info = pathinfo($_FILES['userFile']['name']); $ext = $info['extension']; // get the extension of the file $newname = "newname.".$ext; $target = 'images/'.$newname; move_uploaded_file( $_FILES['userFile']['tmp_name'], $target);
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