473,581 Members | 2,668 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.tx t|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 2287
Markus
6,050 Recognized Expert Expert
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
2274
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 problems: http://www.steve5252.addr.com/
0
787
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 using, oFile.PostedFile.SaveAs(SaveLocation it throws an exception, saying that access to this path was denied How do I resolve this Thanks in...
1
1188
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
17397
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 You very much in advance. try { //create an instance of the WebClient. System.Net.WebClient MyClient = new System.Net.WebClient();
1
1251
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 particular order, nor do they need to be part of a transaction. I'm currently accomplishing this task by iterating through the ArrayList via the foreach...
0
858
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 to develop a web page that uploads files from my computer to a remote server. I tried to do it in many different ways, the last one is: Dim c,s As...
2
2723
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 it on server but i think it's not the right way coz the infected file will also get uploaded. so, i want to know is there any way to do it on...
0
869
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 request identity. ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS 5 or Network Service on IIS 6) that is used if the...
2
8413
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 <input type="file">. I did some research on the internet, telling me that I have two options (on the Servlet side) in order to get the file and store it...
3
1511
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 : Exception Access to the path 'D:\hostingcont\march2010\abc\abc.com\www\attachments\abc.jpg' is denied. I tried to set permission on attachments folder to...
0
7792
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8149
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8175
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6553
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5364
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3805
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3827
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2301
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1403
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.