Jump to content


Photo

file upload problem


  • Please log in to reply
19 replies to this topic

#1 jpratt

jpratt
  • Members
  • PipPipPip
  • Advanced Member
  • 144 posts

Posted 30 August 2006 - 08:16 PM

I have the following script i am working with to upload an image. as far as i can tell the code works fine. When i go to display the page it wont come up and wont give an error, just a blank white page:

			<?php
			if ($_SERVER['REQUEST_METHOD'] != 'POST') {
				$me = $_SERVER['PHP_SELF'];
			?>
			<form name="form1" method="post" action="<?php echo $me;?>" enctype="multipart/form-data">
              <table width="500" border="0" cellspacing="3" cellpadding="0">
                <tr>
                  <td width="256" height="30" align="right" valign="middle"><p align="right"><span class="style1">Comment for Photo</span></p></td>
                  <td width="344" align="left"><input name="textfield" type="text" size="40" /></td>
                </tr>
                <tr>
                  <td height="30" align="right" class="style1">Website Link </td>
                  <td align="left"><input type="text" name="textfield2" /> 
                    <span class="style1">ie. www.google.com</span> </td>
                </tr>
                <tr>
                  <td height="30" align="right"><span class="style1">Photo </span></td>
                  <td align="left"><input type="file" name="imagefile" /></td>
                </tr>
                <tr>
                  <td>&nbsp;</td>
                  <td align="left"><input name="Submit" type="submit" value="Submit" /></td>
                </tr>
              </table>
              </form>
			  <?php
			  }
			  else{
			  if(isset($Submit)){ 
  $file=$_FILES['imagefile']['name']; 
  $filetype=substr($file,-4); 
  if($filetype=="jpeg"){ 
    copy($_FILES['imagefile']['tmp_name'],"UploadImg/".$_FILES['imagefile']['name']) 
    or die("Could not copy"); 
    echo"<br>Upload Complete"; 
    echo"<br>Name:&nbsp;".$_FILES['imagefile']['name'].""; 
    echo"<br>Size:&nbsp;".$_FILES['imagefile']['size'].""; 
    echo"<br>Type:&nbsp;".$_FILES['imagefile']['type']."<br>"; 
  }elseif($filetype==".jpg"){ 
    copy($_FILES['imagefile']['tmp_name'],"UploadImg/".$_FILES['imagefile']['name']) 
    or die("Could not copy"); 
    echo"<br>Upload Complete"; 
    echo"<br>Name:&nbsp;".$_FILES['imagefile']['name'].""; 
    echo"<br>Size:&nbsp;".$_FILES['imagefile']['size'].""; 
    echo"<br>Type:&nbsp;".$_FILES['imagefile']['type']."<br>"; 
  }elseif($filetype==".png"){ 
    copy($_FILES['imagefile']['tmp_name'],"UploadImg/".$_FILES['imagefile']['name']) 
    or die("Could not copy"); 
    echo"<br>Upload Complete"; 
    echo"<br>Name:&nbsp;".$_FILES['imagefile']['name'].""; 
    echo"<br>Size:&nbsp;".$_FILES['imagefile']['size'].""; 
    echo"<br>Type:&nbsp;".$_FILES['imagefile']['type']."<br>"; 
  }elseif($filetype==".gif"){ 
    copy($_FILES['imagefile']['tmp_name'],"UploadImg/".$_FILES['imagefile']['name']) 
    or die("Could not copy"); 
    echo"<br>Upload Complete"; 
    echo"<br>Name:&nbsp;".$_FILES['imagefile']['name'].""; 
    echo"<br>Size:&nbsp;".$_FILES['imagefile']['size'].""; 
    echo"<br>Type:&nbsp;".$_FILES['imagefile']['type']."<br>"; 
  }else{ 
    echo"<br><span class="subtitle">Upload Error</span>"; 
    echo"<br>Could Not Copy, Wrong Filetype (".$_FILES['imagefile']['name'].")<br>"; 
  } 
} 
}
?>

Any ideas?? Please Help!

#2 jpratt

jpratt
  • Members
  • PipPipPip
  • Advanced Member
  • 144 posts

Posted 30 August 2006 - 08:43 PM

page is at www.myplasmaart.com/upload.php

#3 ataria

ataria
  • Members
  • PipPipPip
  • Advanced Member
  • 179 posts

Posted 30 August 2006 - 08:46 PM

I am not a php expert, but, you have two php opening tags...
Try closing the first one.

#4 jpratt

jpratt
  • Members
  • PipPipPip
  • Advanced Member
  • 144 posts

Posted 30 August 2006 - 09:18 PM

all php tags are closed. I dont see a problem.

#5 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 30 August 2006 - 09:19 PM

You have a syntax error on this line:

echo"<br><span class="subtitle">Upload Error</span>";

Here is a cleaner version of your code:

<?php
if ($_SERVER['REQUEST_METHOD'] != 'POST') {
	$me = $_SERVER['PHP_SELF'];
	echo '
	<form name="form1" method="post" action="' . $me . '" enctype="multipart/form-data">
	<table width="500" border="0" cellspacing="3" cellpadding="0">
		<tr>
			<td width="256" height="30" align="right" valign="middle"><p align="right"><span class="style1">Comment for Photo</span></p></td>
			<td width="344" align="left"><input name="textfield" type="text" size="40" /></td>
		</tr>
		<tr>
			<td height="30" align="right" class="style1">Website Link </td>
			<td align="left">
				<input type="text" name="textfield2" /> <span class="style1">ie. www.google.com</span> 
			</td>
		</tr>
		<tr>
			<td height="30" align="right"><span class="style1">Photo </span></td>
			<td align="left"><input type="file" name="imagefile" /></td>
		</tr>
		<tr>
			<td>&nbsp;</td>
			<td align="left"><input name="Submit" type="submit" value="Submit" /></td>
		</tr>
	</table>
	</form>';
} else {
	if (isset($Submit)) { 
		$file = $_FILES['imagefile']['name']; 
		$filetype = substr($file,-4); 
		if ($filetype=="jpeg") { 
			copy($_FILES['imagefile']['tmp_name'],"UploadImg/".$_FILES['imagefile']['name']) or die("Could not copy"); 
			echo "<br>Upload Complete"; 
			echo "<br>Name:&nbsp;".$_FILES['imagefile']['name'].""; 
			echo "<br>Size:&nbsp;".$_FILES['imagefile']['size'].""; 
			echo "<br>Type:&nbsp;".$_FILES['imagefile']['type']."<br>"; 
		} else if ($filetype==".jpg") { 
			copy($_FILES['imagefile']['tmp_name'],"UploadImg/".$_FILES['imagefile']['name']) or die("Could not copy"); 
			echo "<br>Upload Complete"; 
			echo "<br>Name:&nbsp;".$_FILES['imagefile']['name'].""; 
			echo "<br>Size:&nbsp;".$_FILES['imagefile']['size'].""; 
			echo "<br>Type:&nbsp;".$_FILES['imagefile']['type']."<br>"; 
		} else if ($filetype==".png") { 
			copy($_FILES['imagefile']['tmp_name'],"UploadImg/".$_FILES['imagefile']['name']) or die("Could not copy"); 
			echo "<br>Upload Complete"; 
			echo "<br>Name:&nbsp;".$_FILES['imagefile']['name'].""; 
			echo "<br>Size:&nbsp;".$_FILES['imagefile']['size'].""; 
			echo "<br>Type:&nbsp;".$_FILES['imagefile']['type']."<br>"; 
		} else if ($filetype==".gif") { 
			copy($_FILES['imagefile']['tmp_name'],"UploadImg/".$_FILES['imagefile']['name']) or die("Could not copy"); 
			echo "<br>Upload Complete"; 
			echo "<br>Name:&nbsp;".$_FILES['imagefile']['name'].""; 
			echo "<br>Size:&nbsp;".$_FILES['imagefile']['size'].""; 
			echo "<br>Type:&nbsp;".$_FILES['imagefile']['type']."<br>"; 
		} else { 
			echo "<br><span class=\"subtitle\">Upload Error</span>"; 
			echo "<br>Could Not Copy, Wrong Filetype (".$_FILES['imagefile']['name'].")<br>"; 
		} 
	} 
}
?>


#6 jpratt

jpratt
  • Members
  • PipPipPip
  • Advanced Member
  • 144 posts

Posted 30 August 2006 - 09:38 PM

thanks for the clean up. but it still does not function. I have checked my php.ini and verified it allowed uploads. Somthing is still wrong.

#7 jpratt

jpratt
  • Members
  • PipPipPip
  • Advanced Member
  • 144 posts

Posted 31 August 2006 - 12:28 AM

Anyone have any ideas?

#8 jpratt

jpratt
  • Members
  • PipPipPip
  • Advanced Member
  • 144 posts

Posted 31 August 2006 - 02:04 PM

Cant get this thing to work, does anyone have a better way of doing a file upload.

#9 jpratt

jpratt
  • Members
  • PipPipPip
  • Advanced Member
  • 144 posts

Posted 31 August 2006 - 02:32 PM

I have run through my php.ini file, checked with my host to make sure this is allowed, and still cont get this thing to work. I know the post is happening, but nothing is being displayed, no confirmation or denial of upload. Anymore suggestions other than how to clean up my code?

#10 zero118

zero118
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 31 August 2006 - 02:38 PM

Well, one issue may be that when you submit the form it's taking you to copy.php instead of staying at upload.php to continue the script.

#11 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 31 August 2006 - 02:44 PM

please look at the php.net website and look at the correct upload method as from what i can see your setting to meny varables that can be set as one in an array ok.

good luck.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#12 jpratt

jpratt
  • Members
  • PipPipPip
  • Advanced Member
  • 144 posts

Posted 31 August 2006 - 02:49 PM

sorry, i have been testing locally with the code above. The accual page is now at www.myplasmaart.com/upload.php. I am not using anything different that above, except i fixed the echo statement at the end. I am not even getting the "Upload Error" in my else if statement

#13 zero118

zero118
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 31 August 2006 - 02:51 PM

I tried it and it just says that my photo will be approved.

#14 simcoweb

simcoweb
  • Members
  • PipPipPip
  • Advanced Member
  • 1,102 posts
  • LocationCA

Posted 31 August 2006 - 03:05 PM

I tried to upload a .jpg and got this:

Possible file upload attack!
Here is some more debugging info:Array
(
    [userfile] => Array
        (
            [name] => badboys2.sized.gif
            [type] => 
            [tmp_name] => 
            [error] => 2
            [size] => 0
        )

)


#15 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 31 August 2006 - 03:06 PM

this is the correct code to use to test a user file type ok.
$type=($_FILES['userfile']['type']=="video/mpeg");
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#16 zero118

zero118
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 31 August 2006 - 03:12 PM

Yes, that and I believe you're using the wrong function to get the file types.  You sould strip the image string up to the . (dot) and take that extension.  But I'm not too good with file uploads :)

#17 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 31 August 2006 - 03:13 PM

take a quick look at this as you can see from my code you also need to add valadation to it ok.

but look and also go and study from the php.net website remember copy and past is time consumming when you get another project bes to learn properly ok.

You could code the way your coding but if you want to better your self your have to understand arrays and also read sorry i no it's boring but when your earning nice fat pocket load of money that wont matter then.


good luck.

example only look at the code properly .
<?php

// file upload information

$uploaddir ="members_uploads/";

$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);

//set a date sent 

$date_sent=date("d-m-y");

// set a mime valadating 

$blah = getimagesize($userfile);
$type = $blah['mime'];
$width = $blah[0];
$size = $blah[2]=$_FILES['userfile']['size'];



// valadate siz and type

if($size <= 50000) {

if($type) {

// if file correct let file throw and into the folder

if(move_uploaded_file($_FILES['userfile']['tmp_name'],$uploadfile)) {

$userfile_name=addslashes($userfile_name);

$query="insert into members_picture_uploads values('$id','$name','$date_sent','$userfile_name')";

$result=mysql_query($query);


// say thank you if the user has a valid file.

echo "file uploaded thank you<br>";
exit;
}

// echo link for valadating pic
}else{
echo "Wrong file type .jpg or .gif thank you <br><br> <a href ='members_upload_picture_form.php'>Pleae try agin</A>";
}

//echo link for valadating file size
}else{
echo "Wrong file size 50000 bytes only<br><br> <a href ='members_upload_picture_form.php'>Pleae try agin</A>";
}

?>

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#18 jpratt

jpratt
  • Members
  • PipPipPip
  • Advanced Member
  • 144 posts

Posted 31 August 2006 - 03:58 PM

ok i have tried your code and it still will not upload. I have read the entire section on uploads from php.net. When i use your code it always tells me it is not the right file type. I have tried uploading .jpg, .gif. I left out the database code you had in there so it looks like this:

<?php

// file upload information

$uploaddir ="uploadimg/";

$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);


// set a mime valadating 

$blah = getimagesize($userfile);
$type = $blah['mime'];
$width = $blah[0];
$size = $blah[2]=$_FILES['userfile']['size'];



if($size <= 2000000) {

//if($type) {

// if file correct let file throw and into the folder

if(move_uploaded_file($_FILES['userfile']['name'],$uploadfile)) {


// say thank you if the user has a valid file.

echo "file uploaded thank you<br>";
exit;
}

// echo link for valadating pic
}else{
echo "Wrong file type .jpg or .gif thank you <br><br> <a href ='upload.php'>Pleae try again</a>";
}

echo link for valadating file size
}else{
echo "Wrong file size 2000000 bytes only<br><br> <a href ='upload.php'>Pleae try again</a>";
}

?>

This is driving me crazy!

#19 jpratt

jpratt
  • Members
  • PipPipPip
  • Advanced Member
  • 144 posts

Posted 31 August 2006 - 04:02 PM

sorry the "if($type) {" is not commented out.

#20 jpratt

jpratt
  • Members
  • PipPipPip
  • Advanced Member
  • 144 posts

Posted 31 August 2006 - 04:29 PM

ok i went back to my original plan. the code i had before was so close. I do understand arrays, but 3 if statements does not seenm to exsesive. Anyway i am alomost there. with this code I can upload the file if i leave the directory as '', this places the file in my root directory of course. i do have a folder called uploadimg i would like to place them in. when i set my directory in the code to 'uploadimg/' it says it uploaded successfuly but it accually does not do anything. here is what i am using now:

<?php
if ($_SERVER['REQUEST_METHOD'] != 'POST') {
	$me = $_SERVER['PHP_SELF'];
	echo '
	<form name="form1" method="post" action="' . $me . '" enctype="multipart/form-data">
	<table width="500" border="0" cellspacing="3" cellpadding="0">
		<tr>
			<td width="256" height="30" align="right" valign="middle"><p align="right"><span class="style1">Comment for Photo</span></p></td>
			<td width="344" align="left"><input name="textfield" type="text" size="40" /></td>
		</tr>
		<tr>
			<td height="30" align="right" class="style1">Website Link </td>
			<td align="left">
				<input type="text" name="textfield2" /> <span class="style1">ie. www.google.com</span> 
			</td>
		</tr>
		<tr>
			<td height="30" align="right"><span class="style1">Photo </span></td>
			<td align="left"><input type="file" name="imagefile" /></td>
		</tr>
		<tr>
			<td>&nbsp;</td>
			<td align="left"><input name="Submit" type="submit" value="Submit" /></td>
		</tr>
	</table>
	</form>';
} else {
	if (isset($_POST['Submit'])) { 
		$file = $_FILES['imagefile']['name']; 
		$filetype = substr($file,-4); 
		if ($filetype=="jpeg") { 
			copy($_FILES['imagefile']['tmp_name'],'uploadimg/'.$_FILES['imagefile']['name']) or die("Could not copy"); 
			echo "<br>Upload Complete"; 
			echo "<br>Name:&nbsp;".$_FILES['imagefile']['name'].""; 
			echo "<br>Size:&nbsp;".$_FILES['imagefile']['size'].""; 
			echo "<br>Type:&nbsp;".$_FILES['imagefile']['type']."<br>"; 
		} else if ($filetype==".jpg") { 
			copy($_FILES['imagefile']['tmp_name'],'uploadimg/'.$_FILES['imagefile']['name']) or die("Could not copy"); 
			echo "<br>Upload Complete"; 
			echo "<br>Name:&nbsp;".$_FILES['imagefile']['name'].""; 
			echo "<br>Size:&nbsp;".$_FILES['imagefile']['size'].""; 
			echo "<br>Type:&nbsp;".$_FILES['imagefile']['type']."<br>"; 
		} else if ($filetype==".gif") { 
			copy($_FILES['imagefile']['tmp_name'],'uploadimg/'.$_FILES['imagefile']['name']) or die("Could not copy"); 
			echo "<br>Upload Complete"; 
			echo "<br>Name:&nbsp;".$_FILES['imagefile']['name'].""; 
			echo "<br>Size:&nbsp;".$_FILES['imagefile']['size'].""; 
			echo "<br>Type:&nbsp;".$_FILES['imagefile']['type']."<br>"; 
		} else { 
			echo "<br>Upload Error"; 
			echo "<br>Could Not Copy, Wrong Filetype (".$_FILES['imagefile']['name'].")<br>"; 
		} 
	} 
}
?>

Any ideas, im am almost there!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users