Jump to content

[SOLVED] move_uploaded_file()... what am i missing ?


iPixel

Recommended Posts

Im just making this really really simple upload image script.

<?
$action =  isset($_POST['action']) ? $_POST['action'] : null;
if (!is_null($action)) 
{
	$action = $_POST['action'];
}


if($action == "insert") // IF INSERT THEN UPLOAD THE IMAGE THAT WAS POSTED TO THIS POINT
{

	$userfile_name = $_FILES['image']['name']; // filename
	$userfile_tmp = $_FILES['image']['tmp_name']; // temp filename
	$userfile_size = $_FILES['image']['size']; // file size
	$userfile_type = $_FILES['image']['type']; // file type... jpg, gif, etc...

	$directory = 'images/newsletters/'; // Directory where image will be uploaded to

	$prod_img = $direcroty . $userfile_name; // directory/imgname.jpg

	if (!empty($_FILES['image']['name']))
		{
			move_uploaded_file($userfile_tmp, $prod_img);
		}
	else
		{
			echo "You did not chose an image to upload !";
		}	
}
else // IF NOT INSERT OR ANYTHING ELSE SHOW THE UPLOAD FORM
{
	?>
        <h2>  Add e-Newsletter...</h2>
	<table cellpadding="3" cellspacing="0" border="0" style="border: 1px solid #CCCCCC; background-color: #EEEEEE;" width="20%">
	<tr>
	<form action="admin_newsletters.php" method="post" enctype="multipart/form-data">
	<td align="center">
	<input type="file" name="image" /><br />
        <input type="hidden" name="action" value="insert" />
	<input type="submit" value="Upload eNewsletter" />
	</td>
	</form>
	</tr>
	</table>
        <?
}
?>

 

And its not working ... im not sure why, i went to http://us.php.net/manual/en/function.move-uploaded-file.php and unless im blind it seems like this should work ? Any clue why it doesnt.

all the folders for the directory are 777 so its not a permissions problem.

 

Thanks for the help.

Link to comment
Share on other sites

Try this just to see if it thinks the file has been moved..

 

 

<?
$action =  isset($_POST['action']) ? $_POST['action'] : null;
if (!is_null($action)) 
{
	$action = $_POST['action'];
}


if($action == "insert") // IF INSERT THEN UPLOAD THE IMAGE THAT WAS POSTED TO THIS POINT
{

	$userfile_name = $_FILES['image']['name']; // filename
	$userfile_tmp = $_FILES['image']['tmp_name']; // temp filename
	$userfile_size = $_FILES['image']['size']; // file size
	$userfile_type = $_FILES['image']['type']; // file type... jpg, gif, etc...

	$directory = 'images/newsletters/'; // Directory where image will be uploaded to

	$prod_img = $direcroty . $userfile_name; // directory/imgname.jpg

	if (!empty($_FILES['image']['name']))
		{
			if(move_uploaded_file($userfile_tmp, $prod_img)) {
                                  echo 'uploaded';
                                } else {
                                  echo 'error uploading';
                                }
		}
	else
		{
			echo "You did not chose an image to upload !";
		}	
}
else // IF NOT INSERT OR ANYTHING ELSE SHOW THE UPLOAD FORM
{
	?>
        <h2>  Add e-Newsletter...</h2>
	<table cellpadding="3" cellspacing="0" border="0" style="border: 1px solid #CCCCCC; background-color: #EEEEEE;" width="20%">
	<tr>
	<form action="admin_newsletters.php" method="post" enctype="multipart/form-data">
	<td align="center">
	<input type="file" name="image" /><br />
        <input type="hidden" name="action" value="insert" />
	<input type="submit" value="Upload eNewsletter" />
	</td>
	</form>
	</tr>
	</table>
        <?
}
?>

 

 

Regards

Liam

Link to comment
Share on other sites

Try thisd i found a case that show's different errors

 

 

<?
$action =  isset($_POST['action']) ? $_POST['action'] : null;
if (!is_null($action)) 
{
	$action = $_POST['action'];
}


if($action == "insert") // IF INSERT THEN UPLOAD THE IMAGE THAT WAS POSTED TO THIS POINT
{

	$userfile_name = $_FILES['image']['name']; // filename
	$userfile_tmp = $_FILES['image']['tmp_name']; // temp filename
	$userfile_size = $_FILES['image']['size']; // file size
	$userfile_type = $_FILES['image']['type']; // file type... jpg, gif, etc...

	$directory = 'images/newsletters/'; // Directory where image will be uploaded to

	$prod_img = $direcroty . $userfile_name; // directory/imgname.jpg

	if (!empty($_FILES['image']['name']))
		{
			if(move_uploaded_file($userfile_tmp, $prod_img)) {
                                  echo 'uploaded';
                                } else {
                                  echo 'error uploading';
                                  switch ($_FILES['uploadFile'] ['error']) {  
                                    case 1:
                                      print '<p> The file is bigger than this PHP installation allows</p>';
                                      break;
                                    case 2:
                                      print '<p> The file is bigger than this form allows</p>';
                                      break;
                                    case 3:
                                      print '<p> Only part of the file was uploaded</p>';
                                      break;
                                    case 4:
                                      print '<p> No file was uploaded</p>';
                                      break;
                                    }
                                }
		}
	else
		{
			echo "You did not chose an image to upload !";
		}	
}
else // IF NOT INSERT OR ANYTHING ELSE SHOW THE UPLOAD FORM
{
	?>
        <h2>  Add e-Newsletter...</h2>
	<table cellpadding="3" cellspacing="0" border="0" style="border: 1px solid #CCCCCC; background-color: #EEEEEE;" width="20%">
	<tr>
	<form action="admin_newsletters.php" method="post" enctype="multipart/form-data">
	<td align="center">
	<input type="file" name="image" /><br />
        <input type="hidden" name="action" value="insert" />
	<input type="submit" value="Upload eNewsletter" />
	</td>
	</form>
	</tr>
	</table>
        <?
}
?>

 

 

Liam

Link to comment
Share on other sites

i just ran it again with the

print_r($_FILES);

right after the Error Uploading echo..

here is the result ...

 

error uploading

 

Array ( [image] => Array ( [name] => 092707_TESTING.jpg [type] => image/pjpeg [tmp_name] => /tmp/phpfvufdS [error] => 0 => 17894 ) )

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.