Page 1 of 2
upload file problem
Posted: Thu Jun 24, 2004 5:20 pm
by mikotondria
Hi folks..
I recently moved my clints cms file upload scripts to a new server, and it has since stopped working..
The uploading script seems to not be receiving the uploaded file info from the clients form...
<?
$entry = $_POST['entry'];
$title = $_POST['title'];
$title = addslashes($title);
$description = $_POST['description'];
$description = addslashes($description);
//my debugging is..
echo 'file 1 is';
$nameit = $_FILES['image1']['name'];
echo $nameit2;
echo 'file 2 is';
I am submitting to this via POST, but am getting no value for $nameit, so I am assuming that nothing is being received..
the other vars, title, description etc are all being received ok...
Any pointers, anyone : /
Server is running 4.0.2 I believe..
Many thanks in advance
Mike.
Posted: Thu Jun 24, 2004 6:01 pm
by kettle_drum
Is everything ok with the form you use to enter the file? Are you echoing $nameit or $nameit2 ?
Posted: Thu Jun 24, 2004 6:08 pm
by markl999
Server is running 4.0.2 I believe
Create a phpinfo() page and check. If it is 4.0.2 then you won't have the superglobals such as $_POST and $_FILES (they didn't appear until 4.1.0. If it is running 4.0.2 then either get them to upgrade or change hosts, that version is way toooo old

Posted: Thu Jun 24, 2004 6:26 pm
by mikotondria
thanks guys -
Nothing is echoing out of $nameit1 or $nameit 2
(the output is simply...
file 1 isfile 2 is
I ran the phpinfo and were running 4.1.2..
My hosts' help suggested removing the global $files but this hasnt helped..
: /
Posted: Thu Jun 24, 2004 6:33 pm
by markl999
What does var_dump($_FILES); show ?
Posted: Thu Jun 24, 2004 6:39 pm
by mikotondria
hrrm...it would still indicate, nothing is being seen :/..
note: I have 2 images uploading from the form page. The below output is when trying to load only one..
output...
array(1) { ["image1"]=> array(4) { ["name"]=> string(0) "" ["type"]=> string(24) "application/octet-stream" ["tmp_name"]=> string(4) "none" ["size"]=> int(0) } } file 1 isfile 2 is
the 'file 1 is', should be echoing the 'name' of the POSTed file from the $_FILES[...]['name']..
Thanks

Posted: Thu Jun 24, 2004 6:41 pm
by feyd
have you set the encoding type for the form which posts to this script?
Posted: Thu Jun 24, 2004 6:42 pm
by markl999
If this all worked exactly as it is now before you moved hosts then it must be a server configuration problem/difference. Check your phpinfo() page and look at the upload options, eg the upload tmp directory and the max post/upload sizes, see if they look 'ok'. Maybe post a link to your phpinfo() page if that's not a problem.
Posted: Thu Jun 24, 2004 6:52 pm
by mikotondria
Hey

..
OK, its a bit awkward to get to the live output, but I have copied the phpinfo to
http://www.tol23.com/test/phpinfo.htm
Very much appreciate your help with this my friend
Thank you,
Mike.
Posted: Thu Jun 24, 2004 6:55 pm
by markl999
Can't see anything strange or funky in your phpinfo so the next step is to examine the upload form and full upload handling 'stuff'. Can you post your form and the full code that handles it?
Posted: Thu Jun 24, 2004 7:04 pm
by mikotondria
coolio..ok, the page with the form on is...
Code: Select all
<?
$ent = $_GET['entry'];
$link = mysql_connect('localhost', 'k1w1_k1w1sapphir', '******');
if (!$link) {
die('Not connected : ' . mysql_error());
}
// make k1w1_sapphire the current db
$db_selected = mysql_select_db('k1w1_sapphire', $link);
if (!$db_selected) {
die ('Sorry, and error has occurred, please contact the webmaster@sapphirenyc.com. ' . mysql_error());
}
$sql = "SELECT `entry_id`, `description` , `title`, `photo_url` , `photo_url2`". " FROM `reviews` ". "WHERE `entry_id` = $ent";
$result = mysql_query($sql);
$num_results = mysql_num_rows($result);
echo "<form action="update_rev.php" method="POST" enctype="multipart/form-data">";
echo "<span class="artist">";
echo htmlspecialchars(stripslashes($row['entry_id']));
echo "</span>";
echo "<table width=90% cellpadding=8>";
echo "<tr class="description2" bgcolor=#f5f5f5><td width=250>Title</td><td>Description</td><td>Thumbnail</td><td>Review Picture</td></tr>";
for ($i=0; $i<$num_results; $i++)
{
$row = mysql_fetch_array($result);
if ( is_int($i/2)){
echo "<tr bgcolor=#e0e0e0>";
} else {
echo "<tr>";
}
echo "<td valign=top>";
echo "<span>";
echo "<input type"text" name="title" class="dates" size="20" value="".htmlspecialchars(stripslashes($row['title']))."">";
echo "</input>";
echo "</span>";
echo "</td>";
echo "<td width=250 valign=top>";
echo "<span>";
echo "<textarea name="description" class="description2" rows=10 cols=50>";
echo htmlspecialchars(stripslashes($row['description']));
echo "</textarea>";
echo "</span>";
echo "</td>";
echo "<input type="hidden" name="image" value="".htmlspecialchars(stripslashes($row['photo_url']))."">";
echo "<input type="hidden" name="entry" value="".htmlspecialchars(stripslashes($row['entry_id']))."">";
echo "<td valign=top>";
echo "<span class="img2"><img src="images/".htmlspecialchars
stripslashes($row['photo_url']))."" height=100 width=100 <br><br>
<input type="hidden" name="MAX_FILE_SIZE" value="100000"/><p>
<input class="artist" type="file" name="image1" size="25" />";
echo "</td>";
echo "<td valign=top>";
echo "<span class="img2"><img src="images/".htmlspecialchars(stripslashes($row['photo_url2']))."" height=80 width=80 <br><br>
<input type="hidden" name="MAX_FILE_SIZE" value="100000"/><p>
<input class="artist" type="file" name="image1" size="25" />";
echo "</td>";
echo "</tr><tr align=right><td colspan=7><input type="submit" value="Update"/>";
echo "</table>";
echo "</form>";
}
?>
where update_rev.php (where this form info is sent) is...
Code: Select all
<?
$entry = $_POST['entry'];
$title = $_POST['title'];
$title = addslashes($title);
$description = $_POST['description'];
$description = addslashes($description);
//debugging section
var_dump($_FILES);
echo 'file 1 is';
$nameit = $_FILES['image1']['name'];
echo $nameit2;
echo 'file 2 is';
$nameit = $_FILES['image2']['name'];
echo $nameit2;
echo '<p>';
if ($HTTP_POST_FILES['image1']['size'] <=0)
{
echo "<span class="description">No file..</span><br>";
} else {
copy($HTTP_POST_FILES['image1']['tmp_name'],"images/".$HTTP_POST_FILES['image1']['name']) or die ( "Could not copy! - sorry2." );
copy($HTTP_POST_FILES['image2']['tmp_name'],"images/".$HTTP_POST_FILES['image2']['name']) or die ( "Could not copy! - sorry2." );
$image = $_FILES['image1']['name'];
$image2 = $_FILES['image1']['name'];
}
$link = mysql_connect('localhost', 'k1w1_k1w1sapphir', '******');
if (!$link) {
die('Not connected : ' . mysql_error());
}
// make k1w1_sapphire the current db
$db_selected = mysql_select_db('k1w1_sapphire', $link);
if (!$db_selected) {
die ('Sorry, and error has occurred, please contact the webmaster@sapphirenyc.com. ' . mysql_error());
}
$sql = "UPDATE reviews SET description='$description', photo_url='$image', photo_url2='$image2', title='$title' WHERE entry_id = '$entry'";
$result = mysql_query($sql);
if(!$result){
echo "bah-failed";
}
else {
echo "<image src="proc.gif">";
}
?>
Thanks
feyd | please use the
Posted: Thu Jun 24, 2004 7:10 pm
by markl999
Just to rule out a MAX_FILE_SIZE problem, try removing that line from the form as a test.
Posted: Thu Jun 24, 2004 7:11 pm
by feyd
are you aware that you are running a loop where all the file fields are named the same? in fact, there are 2 in each loop that print..
Posted: Thu Jun 24, 2004 7:11 pm
by mikotondria
(ah, neat - yeah sorry about that - thanks

Posted: Thu Jun 24, 2004 7:14 pm
by mikotondria
urm...not sure what you mean by the 'loop' thing.. : /
could you expand, please ?
Thanks
