473,320 Members | 1,991 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Saving an uploaded file with a User-specified name

Hi All.

Anyone plz tell me how can I upload a file with the file name of my choice.
am having problem with this, the file got uploaded but not with the name I wanted to...how can I do this ....please tell me.

Here is the code:

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <title>Uploading...</title>
  4. </head>
  5. <body>
  6. <h1>Uploading file...</h1>
  7. <?php
  8. if ($_FILES['userfile']['error'] > 0)
  9. {
  10.     switch ($_FILES['userfile']['error'])
  11.       {
  12.              case 1: echo 'File exceeded upload_max_filesize'; break;
  13.              case 2: echo 'File exceeded max_file_size'; break;
  14.              case 3: echo 'File only partially uploaded'; break;
  15.              case 4: echo 'No file uploaded'; break;
  16.       }
  17. exit;
  18. }
  19.  
  20. $cr=$_REQUEST[fname];
  21. $upfile = "uploads/$cr/".$_FILES['userfile']['name'] ;
  22.  
  23. if (is_uploaded_file($_FILES['userfile']['tmp_name']))
  24.   {
  25.      if (!move_uploaded_file($_FILES['userfile']['tmp_name'], $upfile)) 
  26.          {
  27.             echo 'Problem: Could not move file to destination directory';
  28.            exit;
  29.         }
  30.   }
  31. else
  32. {
  33.       echo 'Problem: Possible file upload attack. Filename: ';
  34.       echo $_FILES['userfile']['name'];
  35.       exit;
  36. }
  37.  
  38.     echo 'File uploaded successfully<br><br>';
  39.  
  40. echo "<a href='tlecs.php'>click here to continue</a>";
  41.  
  42. echo '<br><hr>';
  43. ?>
  44. </body>
  45. </html>
  46.  


Regards
Sep 24 '07 #1
2 1538
pbmods
5,821 Expert 4TB
Heya, Muddasir.

Please use CODE tags when posting source code:

[CODE=php]
PHP code goes here.
[/CODE]

This is not the first time I've had to ask you.

Changed thread title to better describe the problem (did you know that threads whose titles do not follow the Posting Guidelines actually get FEWER responses?).
Sep 24 '07 #2
kovik
1,044 Expert 1GB
the file got uploaded but not with the name I wanted to
Really? Because according to the code, the name you wanted was the original filename.

[php]$upfile = "uploads/$cr/".$_FILES['userfile']['name'] ;[/php]

If you want to change the filename, it's right there.
Sep 24 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: rohith | last post by:
Hope someone can help with this question. I have a digital camera that will be used to capture photographs for picture ids. My question is whether I can capture the image from a web page...
1
by: terrorix | last post by:
I want to save uploaded file to disk. I have this construction: HttpPostedFile myFile = ((HttpRequest)Request).Files; if (myFile != null) { string fn =...
2
by: Brad | last post by:
I have code which takes an image, uploaded from a web page, and saves it to a database. Now I want to always resize an uploaded image before it is saved to the database. My code to resize is...
12
by: tjonsek | last post by:
I get a generic error (not very helpful) when attempting to save a re-sized image back to its original location. Here is the code snippet: Dim g As System.Drawing.Image =...
4
by: Pedro Leite | last post by:
Good Afternoon. the code below is properly retreiving binary data from a database and saving it. but instead of saving at client machine is saving at the server machine. what is wrong with my...
1
by: hellboss | last post by:
Hi everyone ! Im using asp.net vs05 , I need to save a document file which is been attached or uploaded thru the file upload control which in turn should save the corresponding file into the server...
1
by: radraq | last post by:
Hello, I have just completed a survey in excel which I've uploaded to my website. The propblem is I would like the excel file to open directly online without asking for paswords and save the...
2
by: radraq | last post by:
Hello, I have just completed a survey in excel which I've uploaded to my website. The propblem is I would like the excel file to open directly online without asking for paswords and save the...
1
by: rose | last post by:
Hi I am working in .net 1.1 and trying to save an uploaded file in a directory on another server in a folder under another web application. I am getting different exceptions like Directory not...
7
by: sandeepk84 | last post by:
Hi all... I have file upload option in my web application. I use Struts 2. I wanted to show a preview of the uploaded file to the user. The uploaded file can be of any type like...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.