Page 1 of 1

having some problem related to "upload the file through

Posted: Tue Jun 12, 2007 3:14 am
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]

Posted: Tue Jun 12, 2007 5:01 am
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"]);
}

Posted: Tue Jun 12, 2007 7:17 am
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.

Posted: Tue Jun 12, 2007 8:56 am
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.