Forum Moderators: coopster
<form enctype="multipart/form-data" action="loadmeup.php" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="300000">
<input name="userfile[]" type="file" /><br />
<input name="userfile[]" type="file" /><br />
<input type="submit" />
</form>
When i print "$tot",i get 5? also when i print"$result" i get resource id#3
why is that?
<html>
<head><title>Enter Name and Descriptions of Pics</title></head>
<body>
<h1>Enter Name and Descriptions of Pics</h1>
<form action="view.php" method="post">
<?php
//require "db1.inc";
$dbh=mysql_connect("localhost", "root", "password") or die ('I cannot connect to the database.');
mysql_select_db("mydb");
$uploaddir = 'C:\Program Files\EasyPHP1-8\www\images';
if(isset($uploaddir))
print"I exist";
else
print"I do not exist";
$tot = count($_FILES['userfile']);
print"$tot";
$num = 0;
for($q=0;$q<$tot;$q++){
if ($_FILES['userfile']['name'][$q] == "") continue;
$num = $num + 1;
$sql = "SELECT pic_id FROM pics ORDER BY pic_id DESC LIMIT 1";
$result = mysql_query($sql);
print"$result";
while($i = mysql_fetch_array($result)){
$new_id = $i['pic_id'] + 1;
$new_pic = "$new_id.jpg";
if(isset($new_pic))
print"yes";
else
print"i do not exixt";
}
rest of the code...
because all you have at the point you are trying to print is a pointer to a result set in mysql. It is printing the information it has.
take a read through this page
[php.net...]
specifically the "Return Values" portion
Array
(
[userfile] => Array
(
[name] => Array
(
[0] => Bulls.jpg
[1] => Henry.jpg
)
[type] => Array
(
[0] => image/pjpeg
[1] => image/pjpeg
)
[tmp_name] => Array
(
[0] => C:/Program Files/EasyPHP1-8\tmp\php31.tmp
[1] => C:/Program Files/EasyPHP1-8\tmp\php32.tmp
)
[error] => Array
(
[0] => 0
[1] => 0
)
[size] => Array
(
[0] => 21501
[1] => 9938
)
)
)
so only 2 files are being passed.
My line 24 is
if ($_FILES['userfile']['name'][$q] == "") continue;
My line 36 is
if (move_uploaded_file($_FILES['userfile']['tmp_name'][$q], $uploaddir.$new_pic)) {
Henry.jpg
Notice: Undefined variable: new_pic in c:\program files\easyphp1-8\www\loadmeup.php on line 36
Warning: move_uploaded_file(C:\Program Files\EasyPHP1-8\www\images): failed to open stream: Permission denied in c:\program files\easyphp1-8\www\loadmeup.php on line 36
Warning: move_uploaded_file(): Unable to move 'C:/Program Files/EasyPHP1-8\tmp\php47.tmp' to 'C:\Program Files\EasyPHP1-8\www\images' in c:\program files\easyphp1-8\www\loadmeup.php on line 36
(Array{['userfile']}{['name']}[0]) did not upload! //
// // // Henry.jpg
Name:
Description:
Bulls.jpg
Notice: Undefined variable: new_pic in c:\program files\easyphp1-8\www\loadmeup.php on line 36
Warning: move_uploaded_file(C:\Program Files\EasyPHP1-8\www\images): failed to open stream: Permission denied in c:\program files\easyphp1-8\www\loadmeup.php on line 36
Warning: move_uploaded_file(): Unable to move 'C:/Program Files/EasyPHP1-8\tmp\php48.tmp' to 'C:\Program Files\EasyPHP1-8\www\images' in c:\program files\easyphp1-8\www\loadmeup.php on line 36
(Array{['userfile']}{['name']}[1]) did not upload! //
// // // Bulls.jpg
Name:
Description:
Notice: Undefined offset: 2 in c:\program files\easyphp1-8\www\loadmeup.php on line 24
Notice: Undefined offset: 3 in c:\program files\easyphp1-8\www\loadmeup.php on line 24
Notice: Undefined offset: 4 in c:\program files\easyphp1-8\www\loadmeup.php on line 24
<html>
<head><title>Enter Name and Descriptions of Pics</title></head>
<body>
<h1>Enter Name and Descriptions of Pics</h1>
<form action="view.php" method="post">
<?php
//require "db1.inc";
$dbh=mysql_connect("localhost", "root", "password") or die ('I cannot connect to the database.');
mysql_select_db("mydb");
$uploaddir = 'C:\Program Files\EasyPHP1-8\www\images';
$tot = count($_FILES['userfile']);
for($q=0;$q<$tot;$q++){
if ($_FILES['userfile']['name'][$q] == "") continue;
print_r(($_FILES['userfile']['name'][$q]));
$num = $num + 1;
$sql = "SELECT pic_id FROM pics ORDER BY pic_id DESC LIMIT 1";
$result = mysql_query($sql);
while($i = mysql_fetch_array($result)){
$new_id = $i['pic_id'] + 1;
print"$new_id";
$new_pic = "$new_id.jpg";
}
if (move_uploaded_file($_FILES['userfile']['tmp_name'][$q], $uploaddir.$new_pic)) {
$sql = "INSERT INTO pics ( pic_id , pic_name , descrip )VALUES ('$new_id', NULL , NULL);";
mysql_query($sql);
} else {
print "<strong>($_FILES{['userfile']}{['name']}[$q])</strong> did not upload!";
}
?>
//<div style="clear: both;">
//<a href="/images/<?=$new_pic?>">
//<img src="/images/<?=$new_thumb?>" style="float: left" />
//</a>
<strong><?=$_FILES['userfile']['name'][$q]?></strong><br /><br />
<strong>Name:</strong><br />
<input type="text" name="pic_name[<?=$num?>]" /><br /><br />
<strong>Description:</strong><br />
<textarea name="descrip[<?=$num?>]"></textarea>
<input type="hidden" name="pic_id[<?=$num?>]" value="<?=$new_id?>" />
//</div>
<?php
}
?>
<input type="submit" value="Click to Save Descriptions" />
</form>
</body>
</html>
Should be:
$new_pic = $new_id.'.jpg';
You can also use the curly braces {} like so:
$new_pic = "{$new_id}.jpg";
More details in the strings section [us2.php.net] of the manual.
if (move_uploaded_file($_FILES['userfile']['tmp_name'][$q], $uploaddir.$new_pic)) {
to
$mypic = $uploaddir.$new_pic;
echo $mypic;
if (move_uploaded_file($_FILES['userfile']['tmp_name'][$q], $mypic)) {
just to see if it is correct
I still think it is a path issue
Warning: move_uploaded_file(): Unable to move 'C:/Program Files/EasyPHP1-8\tmp\php47.tmp' to 'C:\Program Files\EasyPHP1-8\www\images' in c:\program files\easyphp1-8\www\loadmeup.php on line 36
the slashes flip flop and the upper and lower case mismatch seems weird in this
Warning: move_uploaded_file(): Unable to move 'C:/Program Files/EasyPHP1-8\tmp\php47.tmp' to 'C:\Program Files\EasyPHP1-8\www\images' in c:\program files\easyphp1-8\www\loadmeup.php on line 36