|
-
Aug 2nd, 2003, 02:29 PM
#1
Thread Starter
Addicted Member
uploading many files !
I am having problem with a page that does the uploading multiple files onto the server . I have succeeded in uploading 1 file but for uploading many files a times seems to be too hard for me .Below is my code , the result of the code is displaying only the text"is not an image file" ( as i check the uploading file is "image/gif" ) . Anyone please tell me where am i wrong ?
PHP Code:
session_start();
require 'function.php';
require 'admin.inc';
if(Check_valid_user())
{
$buttons = get_new_buttons();
$im = new admin();
$im->header('Uploading files' );
$im->Menu($buttons);
// Neu da an vao submit thi kiem tra loi , khong co loi thi cho xuat hien
if($submit)
{
$error = '';
$i=0;
//Lay id trong database
db_connect();
$re = mysql_query("SELECT Max(id) FROM image ");
$kq= mysql_fetch_row($re);
while(($image[$i])&& ($image[$i]!='none'))
{
if($image[$i]["type"]!= "image/gif")
{
$error.="<br> ".$image_name[$i] ."is not an image file .";
$i++;
continue;
}
if($image_size[$i] > 300000)
{
$error .= "<br> ".$image_name[$i] ."is over 300000 bytes.";
$i++;
continue;
}
if($image_size[$i]==0)
{
$error.= "<br> ".$image_name[$i] ."is zero length .";
$i++;
continue;
}
if(!is_uploaded_file($image[$i]))
{
$error.= "<br> Failed to upload ".$image_name[$i]." try again .";
$i++;
continue;
}
$filename="image".($kq[0]+1)."."."jpg";
$upload = "../images/".$filename;
//Thuc hien chuyen thu muc
if(!copy($image[$i],$upload))
{
$error .= "<br> ".$image_name[$i] ." cannot be moved .";
$i++;
continue;
}
else
{
$error.="<br> ".$image_name[$i] ." was uploaded successfully.";
$i++;
continue;
}
$imageurl[$i] = "../images/".$filename;
if($caption[$i]=="")
{
$cap = "Not available";
}
else
{
$cap = $caption[$i];
}
addimage($cap,$imageurl);
$kq[0]++;
}// while
// An vao submit , khong gap loi cho hien thi thong bao thanh cong
$header = "<font color=red>Uploading files </font>";
$body =$error;
$im->below($header,$body);
exit;
}
else // Chua an vao submit
{
$header="<center>
<font size=6 color=#FF0000>Upload images</font></p>
</center>";
$body = " Choose the
images from you computer to upload onto the server ,the images will
automatically be displayed on the Photo gallery page , then everybody can see them .<br>
The caption of the file field will be the
displayed on the right side of the image file in the Photo gallery page .<br>
<form method=POST action=$PHP_SELF>
<table border=1 cellpadding=0 cellspacing=0 style='border-collapse: collapse' bordercolor='#111111' width='100%' height='271'>
<tr>
<td width='51%' height='19' bgcolor='#626BC1'>
<font color='#FFFFFF' size='4'>Images to be uploaded </font><br>
<font color='#FFFFFF' size=2>Click on the Browse button to select the files</font></td>
<td width='50%' height='19' bgcolor='#626BC1'>
<font size='4' color='#FFFFFF'>Caption of the files</font><br>
<font size='2' color='#FFFFFF'>Enter the caption for the image file
on same line </font></td>
</tr>
<tr>
<td width='51%' align='center' >
<p>
<input type='file' name=image[] size='20'><br>
<input type='file' name=image[] size='20'><br>
<input type='file' name=image[] size='20'><br>
<input type='file' name=image[] size='20'><br>
<input type='file' name=image[] size='20'><br>
</tr>
<td width='50%' align='center' >
<input type='text' name='caption[0]' size='36'>
<input type='text' name='caption[1]' size='36'><br>
<input type='text' name='caption[2]' size='36'><br>
<input type='text' name='caption[3]' size='36'><br>
<input type='text' name='caption[4]' size='36'><br>
</tr>
<tr>
<td width='200%' align='center' height='26' colspan='2'>
<input type='submit' value='Submit' name='submit'> </td>
</tr>
</table>
</center>
</form>
</div> ";
$im->below($header,$body);
exit;
}
}
else
{
echo 'you have not logged in ';
}
-
Aug 2nd, 2003, 02:44 PM
#2
Thread Starter
Addicted Member
i had a mistake
if($image_type[$i] !="image/gif")
but this still cannot fix the problem .
-
Aug 2nd, 2003, 02:51 PM
#3
Stuck in the 80s
I already harped on somebody for this today, so I may sound like a broken record, but you're using both deprecated HTML and PHP code.
Look up some information on the superglobals. It'll do you a world of good. Then go to www.w3.org and look up HTML specifications.
As to why you're getting that message...are you sure the files are infact .gif images?
And I'm not sure how the image is getting set to 'none', so try this:
Code:
while(($image[$i]) && ($image[$i] != ''))
{
Unless I missed something.
-
Aug 3rd, 2003, 01:36 AM
#4
Frenzied Member
it will never be an image because like hobo said you are using wrong variables.
PHP Code:
while(($_FILES['image'][$i])&& ($_FILES['image'][$i]!='none'))
{
if($_FILES['image']["type"][$i]!= "image/gif")
and yes it can equal 'none' hobo. always have to check for that.
-
Aug 3rd, 2003, 01:49 AM
#5
Stuck in the 80s
In my scripts, I just use '' instead of 'none' and it works fine.
-
Aug 3rd, 2003, 01:56 AM
#6
Frenzied Member
best to use both, even the manual suggests it
-
Aug 3rd, 2003, 02:05 AM
#7
Stuck in the 80s
ah, yes, the manual. I'll have to give it a look.
-
Aug 3rd, 2003, 02:16 AM
#8
Frenzied Member
great, now I look like an idiot I can't find it anymore where it said that. they must have taken it out.
-
Aug 3rd, 2003, 02:20 AM
#9
Stuck in the 80s
While we're on the subject, what is the type for a jpg?
I've tried 'image/jpg', but it never works?
-
Aug 3rd, 2003, 02:34 AM
#10
Frenzied Member
I think it has to be "image/jpeg"
-
Aug 3rd, 2003, 02:44 PM
#11
Stuck in the 80s
I think I might have tried that, too.
I'll give it another look in a few.
-
Aug 3rd, 2003, 04:07 PM
#12
Stuck in the 80s
I uploaded a jpeg and echoed the type, and it said image/pjpeg. So...I'm guessing that's it?
-
Aug 3rd, 2003, 04:11 PM
#13
Stuck in the 80s
Also, when I try this:
Code:
if ($_FILES['F']['name'][$i] != 'none') {
It doesn't work, but this does:
Code:
if ($_FILES['F']['name'][$i] != '') {
When I use 'none', it validates to true when it should be false (as it should == 'none')
Is this a difference of browser thing? I'm trying it in IE6.
-
Aug 3rd, 2003, 04:38 PM
#14
Frenzied Member
I don't think so,
if ($_FILES['F']['name'][$i] != 'none') {
would be true as you don't want it to be none. I think it may have something to do with the server setup too.
if it was if ($_FILES['F']['name'][$i] != '') { some servers automatically say 'none'. it might also have a lot to do with windows servers.
actually it is the
if ($_FILES['F']['tmp_name'][$i] != 'none') {
that would be name none, not the file name. so it seems a php thing.
-
Aug 3rd, 2003, 05:11 PM
#15
Stuck in the 80s
I have no idea what you're talking about.
What about the pjpeg thing?
-
Aug 3rd, 2003, 07:10 PM
#16
Frenzied Member
oh yeah 
I have never seen it as that.
http://www.iana.org/assignments/media-types/image/
any where I look it doesn't say anything like that. are you sure that wasn't saved as a jpeg 2000? it might have somethign to do with the way the browser read that image.
also
if ($_FILES['F']['tmp_name'][$i] != 'none') {
that is the correct format you want, not the other way as posted on this page. temp_name is assigned by php and it could possible be 'none' and you don't want that.
-
Aug 3rd, 2003, 08:30 PM
#17
Stuck in the 80s
Originally posted by phpman
oh yeah 
I have never seen it as that.
http://www.iana.org/assignments/media-types/image/
any where I look it doesn't say anything like that. are you sure that wasn't saved as a jpeg 2000? it might have somethign to do with the way the browser read that image.
I thought it was odd too. So I just decided to check the file extension and see if it was .gif, .jpg, or .jpeg. But people could always upload a .mp3 or something with the file extension changed, so I was hoping I could figure it out.
Originally posted by phpman
if ($_FILES['F']['tmp_name'][$i] != 'none') {
that is the correct format you want, not the other way as posted on this page. temp_name is assigned by php and it could possible be 'none' and you don't want that.
Alright, that makes sense.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|