Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to upload & Save Files with Desired name

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

like image 264
Moon Avatar asked Aug 18 '10 05:08

Moon


People also ask

How do you upload a document on your computer?

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.

How can I upload something online?

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.


1 Answers

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); 
like image 66
Manie Avatar answered Oct 08 '22 21:10

Manie