473,324 Members | 2,254 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,324 software developers and data experts.

How to upload a predefined filename on a server with PHP

hi
am novice at php but I hope that ye will help me.I have a long list of names of text files.these txt files will be used by swf to displayed on the flash file.the problem is to make a user friendly upload interface that make it easy for people to upload the correct or incorrect txt file name and choose to overwrite a certain text file.example:
this is html form:
Upload a file: /file_location/ |Browse button|
Choose file name |fileName1.txt|or|fileName2.txt|or....
|submit button|

but I cant send the file name option to php to overwrite the existing fileName.
If this is still difficult to understand please tell me.
Thank you.
Oct 31 '10 #1
2 2274
Markus
6,050 Expert 4TB
How are you allowing users to specify the 'correct filename'? an input element?
Oct 31 '10 #2
ill show you better :
html
Expand|Select|Wrap|Line Numbers
  1. <form enctype="multipart/form-data" action="upload.php" method="post">
  2.     <input type="hidden" name="MAX_FILE_SIZE" value="1000000" />
  3.     Choose a file to upload: </br>
  4.     <input name="uploaded_file" type="file" /></br>
  5.  
  6. <select name="nameFile" type="name">
  7. <option value="\mozgaf1.txt">mozgaf</option>
  8. <option value="\mozgaf2.txt">mozgaf2</option>
  9. <option value="\mozgaf3.txt">mozgaf3</option>
  10. </select>
  11.  
  12.  
  13. <input type="submit" name="submit" value="Submit" />
  14.   </form>
  15.  
PhP file looks kind of like this.
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. //check that we have a file
  3. if((!empty($_FILES["uploaded_file"])) && ($_FILES['uploaded_file']['error'] == 0)) {
  4.   //Check if the file is TEXT and it's size is less than 350Kb
  5.   $filename = basename($_FILES['nameFile']['name']);
  6.   $ext = substr($filename, strrpos($filename, '.') + 1);
  7.   if (($ext == "txt") && ($_FILES["nameFile"]["type"] == "text/txt") && 
  8.     ($_FILES["uploaded_file"]["size"] < 350000)) {
  9.     //Determine the path to which we want to save this file
  10.       $newname = dirname(__FILE__).'/upload/'.$filename;
  11.       //Check if the file with the same name is already exists on the server
  12.       if (!file_exists($newname)) {
  13.         //Attempt to move the uploaded file to it's new place
  14.         if ((move_uploaded_file($_FILES['uploaded_file']['tmp_name'],$newname))) {
  15.            echo "It's done! The file has been saved as: ".$newname;
  16.         } else {
  17.            echo "Error: A problem occurred during file upload!";
  18.         }
  19.       } else {
  20.          echo "Error: File ".$_FILES["nameFile"]["name"]." already exists";
  21.       }
  22.   } else {
  23.      echo "Error: Only .txt files under 350Kb are accepted for upload";
  24.   }
  25. } else {
  26.  echo "Error: No file uploaded";
  27. }
  28. ?>
This way it changes the file name that i pick.
Nov 2 '10 #3

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

Similar topics

3
by: Jeff Alu | last post by:
Hi, I'm moving a website to a new location for a friend of mine. The old site http://www.infomercialavails.com Is working fine. However, the php files at the new location seem to be having...
0
by: Reza | last post by:
Hello I have a directory on the server where I like to upload user files. I have used windows explorer and IIS to give full access to this folder. However, everything it comes to loading file...
1
by: Mike | last post by:
Hi i need to find materail a bout how to upload file to the server..... effectively no time out and not connectin los thank
2
by: genc ymeri | last post by:
I'm uploading a text through http server but I keep getting the below error. Is the below error coming from my code or from the http server ???? Any help/tip will be very much appreciated. Thank...
1
by: The Oracle | last post by:
Hi there, I have an ArrayList containing approximately 20,000 database INSERT command objects. Each of these commands needs to be executed. The commands do not need to be executed in any...
0
by: Giulio Simeone | last post by:
Browsing in the web I find a lot of articles that argue: "With ASP.NET 2.0. uploading files is pretty easy!". I spent on that problem last three days but didn't found my way through it. I have...
2
by: Kausar | last post by:
Hello All, I want to know how to scan the files before uploading it to the server in ASP.NET 2.0 application. One work arround i thought is to allow to upload in some temporary folder then sacn...
0
by: Rizwan Ahmed | last post by:
While trying to upload a file to the server I got an exception as below: ASP.NET is not authorized to access the requested resource. Consider granting access rights to the resource to the ASP.NET...
2
by: tranceluv | last post by:
Hey guys. I am currently working on a project in JSP/Java Servlets, hope this is the right section. So, my problem regards mainly the form through which I will let the user input a file using...
3
by: vinaypratap | last post by:
hi everybody, I am trying to upload a file on server using fileupload control in asp.net 3.5. On local machine code is working fine, but when uploaded on server, it gives exception as :...
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...
0
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...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
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
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.