Page 1 of 1

I don't understand what is wrong

Posted: Fri Oct 13, 2006 10:33 am
by devilduckie
JayBird | 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]


Hi!

I'm trying to write a script that will upload files to the server on my website. But I getting this annoying errer message that I don't under stand. Can somebody help me solve it please?  

The error message is:

[quote]
Warning: move_uploaded_file(/home/uploads/lecture13.pdf): failed to open stream: No such file or directory in /home/emergosim/scripts/laddaupp.php on line 51

Warning: move_uploaded_file(): Unable to move '/tmp/phpaqBy9p' to '/home/uploads/lecture13.pdf' in /home/emergosim/scripts/laddaupp.php on line 51
[/quote]

I'll supply you with the code aswell:

Code: Select all

<?php
		$folder = $_POST['folder'];
		$dok_root = "home/dokument/";
		$path = "";
		
		switch ($folder)
		{
			case "nya_versioner":
				$path = "$dok_root" . "modeller/nya_versioner/";
			break;
			case "generella_versioner":
				$path = "$dok_root" . "modeller/generella_versioner/";
			break;	
			case "gamla_versioner":
				$path = "$dok_root" . "modeller/gamla_versioner/";
			break;
			case "program":
				$path = "$dok_root" . "modeller/program/";
			break;	
			case "flodesmodeller":
				$path = "$dok_root" . "resurser/presentationsmaterial/flodesmodeller/";
			break;	
			case "handbocker":
				$path = "$dok_root" . "resurser/presentationsmaterial/handbocker/";
			break;	
			case "powerpoint":
				$path = "$dok_root" . "resurser/presentationsmaterial/powerpoint/";
			break;	
			case "statistikmallar":
				$path = "$dok_root" . "resurser/statistikmallar/";
			break;
			case "informationsbehov":
				$path = "$dok_root" . "resurser/informationsbehov/";
			break;	
		}
		
		$fullpathname = $path . basename($_FILES['uploadFile']['name']);
			
		$result = move_uploaded_file($_FILES['uploadFile']['tmp_name'], "$fullpathname");
		
		echo "$result";
		
	?>
Hopefully someone can help me translate what the server i trying to tell me. By the way, the file permissions on all the folders that I wan't to upload to are 757.


JayBird | 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: Fri Oct 13, 2006 10:45 am
by RobertGonzalez
That means it cannot find the file you are trying to upload (I think). For testing, change this code:

Code: Select all

$fullpathname = $path . basename($_FILES['uploadFile']['name']);
         
      $result = move_uploaded_file($_FILES['uploadFile']['tmp_name'], "$fullpathname");
      
      echo "$result";
To this

Code: Select all

<?php
      $fullpathname = $path . basename($_FILES['uploadFile']['name']);
         
      //$result = move_uploaded_file($_FILES['uploadFile']['tmp_name'], "$fullpathname");
      echo $_FILES['uploadFile']['tmp_name'], "$fullpathname";
      
      //echo "$result"; 
?>
Report back what you are seeing on the screen.

Posted: Sun Oct 15, 2006 3:04 am
by devilduckie
Everah wrote:That means it cannot find the file you are trying to upload (I think). For testing, change this code:

Code: Select all

$fullpathname = $path . basename($_FILES['uploadFile']['name']);
         
      $result = move_uploaded_file($_FILES['uploadFile']['tmp_name'], "$fullpathname");
      
      echo "$result";
To this

Code: Select all

<?php
      $fullpathname = $path . basename($_FILES['uploadFile']['name']);
         
      //$result = move_uploaded_file($_FILES['uploadFile']['tmp_name'], "$fullpathname");
      echo $_FILES['uploadFile']['tmp_name'], "$fullpathname";
      
      //echo "$result"; 
?>
Report back what you are seeing on the screen.
This is the result I get on screen when running the script:
/tmp/phpTGe6G3home/dokument/modeller/nya_versioner/lecture13.pdf
It seems to work since it gives me the name of the temporary file and the correct value of the variable that I defined.

Posted: Sun Oct 15, 2006 8:07 am
by feyd
The error would suggest that /home/dokument or /home/uploads doesn't exist. Although your error appears to point at different code then that posted.

Posted: Sun Oct 15, 2006 9:23 am
by RobertGonzalez
Do the folder(s) exist that you are trying to put these files into? Are their permissions set properly? Also, I noticed that your original error message differes slightly from the file name you recently posted. That may mean that something is not resolving properly in the code.

Posted: Mon Oct 16, 2006 2:46 pm
by devilduckie
Sorry guys. My mistake. I copied an old error message into the original post. This one is correct though:
Warning: move_uploaded_file(home/dokument/modeller/nya_versioner/lecture13.pdf): failed to open stream: No such file or directory in /home/emergosim/scripts/laddaupp.php on line 53

Warning: move_uploaded_file(): Unable to move '/tmp/phpJ008im' to 'home/dokument/modeller/nya_versioner/lecture13.pdf' in /home/emergosim/scripts/laddaupp.php on line 53
And the code is this:

Code: Select all

<?php
		$folder = $_POST['folder'];
		$dok_root = "home/dokument/";
		$path = "";
		
		switch ($folder)
		{
			case "nya_versioner":
				$path = "$dok_root" . "modeller/nya_versioner/";
			break;
			case "generella_versioner":
				$path = "$dok_root" . "modeller/generella_versioner/";
			break;	
			case "gamla_versioner":
				$path = "$dok_root" . "modeller/gamla_versioner/";
			break;
			case "program":
				$path = "$dok_root" . "modeller/program/";
			break;	
			case "flodesmodeller":
				$path = "$dok_root" . "resurser/presentationsmaterial/flodesmodeller/";
			break;	
			case "handbocker":
				$path = "$dok_root" . "resurser/presentationsmaterial/handbocker/";
			break;	
			case "powerpoint":
				$path = "$dok_root" . "resurser/presentationsmaterial/powerpoint/";
			break;	
			case "statistikmallar":
				$path = "$dok_root" . "resurser/statistikmallar/";
			break;
			case "informationsbehov":
				$path = "$dok_root" . "resurser/informationsbehov/";
			break;	
		}
		
		$fullpathname = $path . basename($_FILES['uploadFile']['name']);
		
		$result = move_uploaded_file($_FILES['uploadFile']['tmp_name'], "$fullpathname");
		
		echo "$result";
		
	?>
The folders do exist on the server and the permissions are all set to 757. Could there be a problem for PHP to find the website root with the path that I use. Is it correct to write "home/..." to address the root for the website on a linux server running apache?

Posted: Mon Oct 16, 2006 2:59 pm
by feyd
does the following exist?

Code: Select all

echo getcwd() . dirname($path);
(place that code after $path is finalized.)

Posted: Mon Oct 16, 2006 4:15 pm
by devilduckie
feyd wrote:does the following exist?

Code: Select all

echo getcwd() . dirname($path);
(place that code after $path is finalized.)
That code outputs this:
/home/emergosim/scriptshome/dokument/modeller

Posted: Mon Oct 16, 2006 4:36 pm
by feyd
So the question is: does /home/emergosim/scripts/home/dokument/modeller exist? That's what you're asking for PHP to store the file into.

Posted: Mon Oct 16, 2006 5:10 pm
by devilduckie
feyd wrote:So the question is: does /home/emergosim/scripts/home/dokument/modeller exist? That's what you're asking for PHP to store the file into.
Ok. That explains it. I changed the $path variable from "home/dokument" to "../dokument". That did the trick. Thanks for helping me guys. Sometimes you just get into a hole where you don't see the way out so you need someone to show you the way.

Thanks a lot :D

Posted: Mon Oct 16, 2006 7:06 pm
by RobertGonzalez
devilduckie wrote:Sometimes you just get into a hole where you don't see the way out so you need someone to show you the way.
Hence the progressive growth of these fine forums. Image