jpratt Posted August 30, 2006 Share Posted August 30, 2006 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:[code] <?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> </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: ".$_FILES['imagefile']['name'].""; echo"<br>Size: ".$_FILES['imagefile']['size'].""; echo"<br>Type: ".$_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: ".$_FILES['imagefile']['name'].""; echo"<br>Size: ".$_FILES['imagefile']['size'].""; echo"<br>Type: ".$_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: ".$_FILES['imagefile']['name'].""; echo"<br>Size: ".$_FILES['imagefile']['size'].""; echo"<br>Type: ".$_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: ".$_FILES['imagefile']['name'].""; echo"<br>Size: ".$_FILES['imagefile']['size'].""; echo"<br>Type: ".$_FILES['imagefile']['type']."<br>"; }else{ echo"<br><span class="subtitle">Upload Error</span>"; echo"<br>Could Not Copy, Wrong Filetype (".$_FILES['imagefile']['name'].")<br>"; } } }?>[/code]Any ideas?? Please Help! Link to comment https://forums.phpfreaks.com/topic/19202-file-upload-problem/ Share on other sites More sharing options...
jpratt Posted August 30, 2006 Author Share Posted August 30, 2006 page is at www.myplasmaart.com/upload.php Link to comment https://forums.phpfreaks.com/topic/19202-file-upload-problem/#findComment-83112 Share on other sites More sharing options...
ataria Posted August 30, 2006 Share Posted August 30, 2006 I am not a php expert, but, you have two php opening tags...Try closing the first one. Link to comment https://forums.phpfreaks.com/topic/19202-file-upload-problem/#findComment-83117 Share on other sites More sharing options...
jpratt Posted August 30, 2006 Author Share Posted August 30, 2006 all php tags are closed. I dont see a problem. Link to comment https://forums.phpfreaks.com/topic/19202-file-upload-problem/#findComment-83135 Share on other sites More sharing options...
hitman6003 Posted August 30, 2006 Share Posted August 30, 2006 You have a syntax error on this line:[code]echo"<br><span class="subtitle">Upload Error</span>"; [/code]Here is a cleaner version of your code:[code]<?phpif ($_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> </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: ".$_FILES['imagefile']['name'].""; echo "<br>Size: ".$_FILES['imagefile']['size'].""; echo "<br>Type: ".$_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: ".$_FILES['imagefile']['name'].""; echo "<br>Size: ".$_FILES['imagefile']['size'].""; echo "<br>Type: ".$_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: ".$_FILES['imagefile']['name'].""; echo "<br>Size: ".$_FILES['imagefile']['size'].""; echo "<br>Type: ".$_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: ".$_FILES['imagefile']['name'].""; echo "<br>Size: ".$_FILES['imagefile']['size'].""; echo "<br>Type: ".$_FILES['imagefile']['type']."<br>"; } else { echo "<br><span class=\"subtitle\">Upload Error</span>"; echo "<br>Could Not Copy, Wrong Filetype (".$_FILES['imagefile']['name'].")<br>"; } } }?>[/code] Link to comment https://forums.phpfreaks.com/topic/19202-file-upload-problem/#findComment-83136 Share on other sites More sharing options...
jpratt Posted August 30, 2006 Author Share Posted August 30, 2006 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. Link to comment https://forums.phpfreaks.com/topic/19202-file-upload-problem/#findComment-83145 Share on other sites More sharing options...
jpratt Posted August 31, 2006 Author Share Posted August 31, 2006 Anyone have any ideas? Link to comment https://forums.phpfreaks.com/topic/19202-file-upload-problem/#findComment-83213 Share on other sites More sharing options...
jpratt Posted August 31, 2006 Author Share Posted August 31, 2006 Cant get this thing to work, does anyone have a better way of doing a file upload. Link to comment https://forums.phpfreaks.com/topic/19202-file-upload-problem/#findComment-83474 Share on other sites More sharing options...
jpratt Posted August 31, 2006 Author Share Posted August 31, 2006 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? Link to comment https://forums.phpfreaks.com/topic/19202-file-upload-problem/#findComment-83497 Share on other sites More sharing options...
zero118 Posted August 31, 2006 Share Posted August 31, 2006 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. Link to comment https://forums.phpfreaks.com/topic/19202-file-upload-problem/#findComment-83501 Share on other sites More sharing options...
redarrow Posted August 31, 2006 Share Posted August 31, 2006 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. Link to comment https://forums.phpfreaks.com/topic/19202-file-upload-problem/#findComment-83502 Share on other sites More sharing options...
jpratt Posted August 31, 2006 Author Share Posted August 31, 2006 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 Link to comment https://forums.phpfreaks.com/topic/19202-file-upload-problem/#findComment-83507 Share on other sites More sharing options...
zero118 Posted August 31, 2006 Share Posted August 31, 2006 I tried it and it just says that my photo will be approved. Link to comment https://forums.phpfreaks.com/topic/19202-file-upload-problem/#findComment-83508 Share on other sites More sharing options...
simcoweb Posted August 31, 2006 Share Posted August 31, 2006 I tried to upload a .jpg and got this:[code]Possible file upload attack!Here is some more debugging info:Array( [userfile] => Array ( [name] => badboys2.sized.gif [type] => [tmp_name] => [error] => 2 [size] => 0 ))[/code] Link to comment https://forums.phpfreaks.com/topic/19202-file-upload-problem/#findComment-83516 Share on other sites More sharing options...
redarrow Posted August 31, 2006 Share Posted August 31, 2006 this is the correct code to use to test a user file type ok.$type=($_FILES['userfile']['type']=="video/mpeg"); Link to comment https://forums.phpfreaks.com/topic/19202-file-upload-problem/#findComment-83517 Share on other sites More sharing options...
zero118 Posted August 31, 2006 Share Posted August 31, 2006 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 :) Link to comment https://forums.phpfreaks.com/topic/19202-file-upload-problem/#findComment-83518 Share on other sites More sharing options...
redarrow Posted August 31, 2006 Share Posted August 31, 2006 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 .[code]<?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 typeif($size <= 50000) {if($type) {// if file correct let file throw and into the folderif(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>";}?>[/code] Link to comment https://forums.phpfreaks.com/topic/19202-file-upload-problem/#findComment-83520 Share on other sites More sharing options...
jpratt Posted August 31, 2006 Author Share Posted August 31, 2006 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:[code]<?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 folderif(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>";}?>[/code]This is driving me crazy! Link to comment https://forums.phpfreaks.com/topic/19202-file-upload-problem/#findComment-83549 Share on other sites More sharing options...
jpratt Posted August 31, 2006 Author Share Posted August 31, 2006 sorry the "if($type) {" is not commented out. Link to comment https://forums.phpfreaks.com/topic/19202-file-upload-problem/#findComment-83553 Share on other sites More sharing options...
jpratt Posted August 31, 2006 Author Share Posted August 31, 2006 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:[code]<?phpif ($_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> </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: ".$_FILES['imagefile']['name'].""; echo "<br>Size: ".$_FILES['imagefile']['size'].""; echo "<br>Type: ".$_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: ".$_FILES['imagefile']['name'].""; echo "<br>Size: ".$_FILES['imagefile']['size'].""; echo "<br>Type: ".$_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: ".$_FILES['imagefile']['name'].""; echo "<br>Size: ".$_FILES['imagefile']['size'].""; echo "<br>Type: ".$_FILES['imagefile']['type']."<br>"; } else { echo "<br>Upload Error"; echo "<br>Could Not Copy, Wrong Filetype (".$_FILES['imagefile']['name'].")<br>"; } } }?>[/code]Any ideas, im am almost there! Link to comment https://forums.phpfreaks.com/topic/19202-file-upload-problem/#findComment-83576 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.