...

View Full Version : Image not being passed through form



blackrain87
09-14-2011, 06:09 PM
Hello there,

I have a little compact image upload page. The only problem with it is the image is not being passed through the form. I'm not sure why, I have used this same script before in multiple places, everything is the same, just doesn't work.


Here is the script side.


$current_image=$_FILES['image1']['name'];
$extension = substr(strrchr($current_image, '.'), 1);
if (($extension!= "jpg") && ($extension != "jpeg") && ($extension != "png"))
{
die('Restricted Extension, did not upload.');
}

$limit_size = 100000;
$file_size=$_FILES['image1']['size'];
if($file_size >= $limit_size)
{
die('Your file is too large, please pick a smaller file');
}
$time1 = date("fYhis");
$new_image = $time1 . "." . $extension;
$destination="images/".$new_image;
$action = copy($_FILES['image1']['tmp_name'], $destination);
if (!$action)
{
die('An error occured, please try again later.');
}


Here is the form


echo '<form name="upload" method="post" action="index.php?page=p_upload&action=upload">';
echo 'Picture Name: <input type=text" name="name"><br />';
echo 'File: <input type="file" name="image1"><br />';
echo 'Privacy Settings: <select name="privacy"><option value="Everyone">Everyone</option><option value="Friends">Friends Only</option><option value="Me">Only Me</option></select><br />';
echo '<input type="submit" value="Upload"></form>';



If anyone can point me in a direction to solving this, it will be much appreciated.

myfayt
09-14-2011, 07:25 PM
Which error are you getting?

tangoforce
09-14-2011, 07:41 PM
$action = copy($_FILES['image1']['tmp_name'], $destination);



That should be move_uploaded_file().

blackrain87
09-19-2011, 09:02 PM
The error is that the file extension is restricted. That is because there is no file being passed!

When I echo out the variable $current_image, it is blank. It is as if it is never being passed through the form. I have never had this happen before.

mlseim
09-19-2011, 09:27 PM
<form name="upload" method="post" action="index.php?page=p_upload&action=upload">

Needs to have multi-part ...

<form name="upload" method="post" action="index.php" enctype="multipart/form-data">

and don't use those URL variables ... those need to be hidden in the form ...

<form name="upload" method="post" action="index.php" enctype="multipart/form-data">
<input type="hidden" name="page" value="p_upload">
<input type="hidden" name="action" value="upload">

and finally ... how are you reading those form variables in your script?
I don't see any $_POST['xxx'] references for your form variable names.



.

blackrain87
09-20-2011, 06:31 AM
Ah thank you! Such a little part that I forgot can make all the difference.

And the $_POST variables were called earlier on the page.


Thanks again!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum