Why am I getting this error?

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
someguyhere
Forum Contributor
Posts: 181
Joined: Sun Jul 27, 2008 3:24 pm

Why am I getting this error?

Post by someguyhere »

I thought it might be a permissions thing, but I've changed the folder to 775 and still no dice. If it makes a difference, the form is currently in the root, but I've tried it in the same folder as the plugin (/wp-content/plugins/wp-members-pages/) and I get the same error. Any idea what might be wrong here?

Error message:

Warning: move_uploaded_file(/wp-content/plugins/wp-members-pages/images/testface.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in /home/efarrell/public_html/app.php on line 15

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpTNgGma' to '/wp-content/plugins/wp-members-pages/images/testface.jpg' in /home/efarrell/public_html/app.php on line 15
There was an error uploading your headshot, please try again!There was an error uploading your logo, please try again!

PHP code:

Code: Select all

<?php

if(isset($_POST['firstname'])){

	// Where the file is going to be placed 
	$target_path = "/wp-content/plugins/wp-members-pages/images/";
	
	/* headshot */
	$target_path = $target_path . basename( $_FILES['headshot']['name']); 
	
	$target_path = "/wp-content/plugins/wp-members-pages/images/";
	
	$target_path = $target_path . basename( $_FILES['headshot']['name']); 
	
	if(move_uploaded_file($_FILES['headshot']['tmp_name'], $target_path)) {
	    echo "The file ".  basename( $_FILES['headshot']['name']). 
	    " has been uploaded";
	print_r($_POST);
	} else{
	    echo "There was an error uploading your headshot, please try again!";
	}
	
	/* logo */
	$target_path = $target_path . basename( $_FILES['logo']['name']); 
	
	$target_path = "/wp-content/plugins/wp-members-pages/images/";
	
	$target_path = $target_path . basename( $_FILES['logo']['name']); 
	
	if(move_uploaded_file($_FILES['']['tmp_name'], $target_path)) {
	    echo "The file ".  basename( $_FILES['']['name']). 
	    " has been uploaded";
	print_r($_POST);
	} else{
	    echo "There was an error uploading your logo, please try again!";
	}

}

if (empty($_POST['firstname'])){

	echo '<form enctype="multipart/form-data" action="" method="post">';
	echo '<input type="text" name="firstname" /><br />';
	echo '<input name="headshot" type="file" /><br />';
	echo '<input name="logo" type="file" /><br />';
	echo '<input type="submit" value="Upload File" />';
	echo '</form>';

}

?>
someguyhere
Forum Contributor
Posts: 181
Joined: Sun Jul 27, 2008 3:24 pm

Re: Why am I getting this error?

Post by someguyhere »

Any ideas?
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Why am I getting this error?

Post by AbraCadaver »

You probably want one of these (not sure of your structure):

Code: Select all

$target_path = '/home/efarrell/public_html/wp-content/plugins/wp-members-pages/images/';
//or
$target_path = 'wp-content/plugins/wp-members-pages/images/';
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Why am I getting this error?

Post by Jonah Bron »

[text]Warning: move_uploaded_file(/wp-content/plugins/wp-members-pages/images/testface.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in /home/efarrell/public_html/app.php on line 15[/text]
That sounds like there was no file uploaded. Do you get the error when you try to upload a file, or all the time?
someguyhere
Forum Contributor
Posts: 181
Joined: Sun Jul 27, 2008 3:24 pm

Re: Why am I getting this error?

Post by someguyhere »

AbraCadaver wrote:You probably want one of these (not sure of your structure):

Code: Select all

$target_path = '/home/efarrell/public_html/wp-content/plugins/wp-members-pages/images/';
//or
$target_path = 'wp-content/plugins/wp-members-pages/images/';
I used the first option and it works perfectly. Any idea why the second option wouldn't though?
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Why am I getting this error?

Post by Jonah Bron »

Apparently the relative URL was incorrect.
Post Reply