I don't understand what is wrong

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
User avatar
devilduckie
Forum Newbie
Posts: 9
Joined: Thu Sep 14, 2006 3:37 pm

I don't understand what is wrong

Post 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]
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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.
User avatar
devilduckie
Forum Newbie
Posts: 9
Joined: Thu Sep 14, 2006 3:37 pm

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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.
User avatar
devilduckie
Forum Newbie
Posts: 9
Joined: Thu Sep 14, 2006 3:37 pm

Post 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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

does the following exist?

Code: Select all

echo getcwd() . dirname($path);
(place that code after $path is finalized.)
User avatar
devilduckie
Forum Newbie
Posts: 9
Joined: Thu Sep 14, 2006 3:37 pm

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
User avatar
devilduckie
Forum Newbie
Posts: 9
Joined: Thu Sep 14, 2006 3:37 pm

Post 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
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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
Post Reply