Page 1 of 1

Why am I getting this error?

Posted: Tue Feb 22, 2011 9:25 pm
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>';

}

?>

Re: Why am I getting this error?

Posted: Wed Feb 23, 2011 10:46 am
by someguyhere
Any ideas?

Re: Why am I getting this error?

Posted: Wed Feb 23, 2011 10:49 am
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/';

Re: Why am I getting this error?

Posted: Wed Feb 23, 2011 11:10 am
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?

Re: Why am I getting this error?

Posted: Wed Feb 23, 2011 11:35 am
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?

Re: Why am I getting this error?

Posted: Wed Feb 23, 2011 1:15 pm
by Jonah Bron
Apparently the relative URL was incorrect.