having some problem related to "upload the file through

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
haiderips
Forum Newbie
Posts: 4
Joined: Sat Jun 02, 2007 9:08 am

having some problem related to "upload the file through

Post by haiderips »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


hello friends ,
    i am trying the upload a text file through php code , but getting some error,
 my code is same as
  html form 

[syntax="html"]
<html>
<body>
<form action="upload.php" method="post" enctype="multipart/form-data">

<input type="file" name="file"> 
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>
and php script is[/syntax]

Code: Select all

<?php

   echo "Upload: " . $_FILES["file"]["name"];
    echo "Type: " . $_FILES["file"]["type"];
    echo "Size: " . ($_FILES["file"]["size"] / 1024);
    echo "Temp file: " . $_FILES["file"]["tmp_name"] ; 

 if (file_exists("upload/" . $_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists. ";
      }
    else
      {
      move_uploaded_file($_FILES["file"]["tmp_name"],"upload/" . $_FILES["file"]["name"]);
            }
     
?>
on executing it , i am getting the error

Warning: move_uploaded_file(upload/todays shedule.txt) [function.move-uploaded-file]: failed to open stream: No such file or directory in C:\Inetpub\wwwroot\forum\upload.php on line 14

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\WINDOWS\TEMP\phpFE.tmp' to 'upload/todays shedule.txt' in C:\Inetpub\wwwroot\forum\upload.php on line 14

i did each and every possibility to execute it, but could not get susscess.
please try to solve my problem


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Last edited by haiderips on Wed Jun 20, 2007 2:28 am, edited 1 time in total.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

please try

Code: Select all

else {
  is_readable($_FILES["file"]["tmp_name"]) or die('cannot read source file');
  is_dir('upload') or die('there is no directory "upload" in '.getcwd());
  is_writable('upload') or die('no write permission on "upload"');
	
  move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]);
}
haiderips
Forum Newbie
Posts: 4
Joined: Sat Jun 02, 2007 9:08 am

Post by haiderips »

thanks ,
i got solution of my problem to some extent, but the some problem is still,
my code is same as

Code: Select all

<?php
		
	echo "Upload: " . $_FILES["file"]["name"]."<br>"; 
	echo "Type: " . $_FILES["file"]["type"]."<br>"; 
	echo "Size: " . ($_FILES["file"]["size"] / 1024)."<br>"; 
	echo "Temp file: " . $_FILES["file"]["tmp_name"] ; 
		
	if (file_exists("upload/" . $_FILES["file"]["name"])) 
	   { 
	          echo $_FILES["file"]["name"] . " already exists. "; 
	   } 
	else 
	  { 
	           is_readable($_FILES["file"]["tmp_name"]) or die('cannot read source file'); 
	           is_dir('test') or die('there is no directory "test" in '.getcwd()); 
	           is_writable('upload') or die('no write permission on "upload"'); 
				
	           move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]); 
	  } 

?> 
 and the error is 
   [b]no write permission on "upload"[/b]

i repetedly remove the read only properties of the directory , but allways read only properties of the directory came in to existence, so please give me suggestion to remove this read only properties.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Talk to your host.

Also, use basename() on the file's original name as some browsers give full path instead of just file name.
Post Reply