Jump to content

steveclondon

Members
  • Posts

    161
  • Joined

  • Last visited

    Never

Everything posted by steveclondon

  1. see my code in this link to see if that helps. http://www.phpfreaks.com/forums/index.php/topic,109671.0.html
  2. im not familar with easy php im sorry to say. I know that when I work on apache my uplaod script works and when I use it on a windows server it doesn't. I have put the code here. It will take the file name put it in a temporary folder and rename using a random number. It will also make sure that the image name doesn't have spaces etc. It will check the type of file and will only let image files be uploaded. There is a second part that i have not put here so that if the file is ok it will move it from the temp folder to the normal one. This code does work I use it on a number of sites. It isn't pretty however, i have not cleaned it up and it is as i use it. Don't take to much notice of my comments in it as I don't always update these when I change bits. This should help you though. [code] <?php $error_upload_form=FALSE; if (isset($_FILES['userfile']['name'])) { $amount=strlen($_FILES['userfile']['name']);  } else { $amount=0; } if ($amount>0) { $file=$_FILES['userfile']; $pos = strrpos($file["name"], "."); #echo 'pos is '.$pos; $file['raw_name'] = substr($file["name"], 0, $pos); $file["extention"] = substr($file["name"], $pos, strlen($file["name"])); $file["raw_name"] = ereg_replace("[^a-z0-9._]", "", str_replace(" ", "_", str_replace("%20", "_", strtolower($file["raw_name"])))); #echo 'the file type is '.$file['type']; $type = explode("/", $file['type']); #echo var_dump($file); if ($type[0]=='image') { if ($file['error']==0) { $image_error=FALSE;  } else { $image_error=TRUE; $image_error_code=$file['error']; } } else { #echo 'the error has been activated'; $image_error=TRUE;  if ($image_error_code==NULL) { $image_error_code=$file['error'];  } } if ($image_error==FALSE) { $filetype=NULL; switch($type[1]) { case 'jpeg': $filetype='.jpg'; break; case 'gif': $filetype='.gif'; break; case 'pjpeg'; $filetype='.jpg'; case 'bmp'; $filetype='.bmp'; case 'png'; $filetype='.png'; case 'jpg'; $filetype='.jpg'; } // switch // perhaps see if filetype = null so no match then produce an error with a different error code. if ($filetype==NULL) { if ($image_error_code==NULL) { #echo 'error 8'; $image_error_code=8;    } $image_error=TRUE;    } #echo 'The file type is '.$filetype; } if ($image_error==FALSE) { $rand=rand(0,9999); $finished_name=$file['raw_name'].'_'.$rand; //check the image folder for $check=file_exists('images/advert/'.$finished_name.$filetype); if ($check==TRUE) { $image_error_code=9; $image_error=TRUE;    } } if ($image_error==FALSE) { $uploaddir = 'tmp/'; $uploadfile = $uploaddir . basename($finished_name.$filetype); #echo '<pre>'; if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {   #echo "File is valid, and was successfully uploaded.\n";   } else {   #echo "Possible file upload attack!\n";   $image_error=TRUE;   $image_error_code=10; } } //************************************************************************** // if not error I will set a session varible pointing to the image. // if it is an error this will not be present. We will also show up a form asking them to enter a pic if error and error message // on next page if confirm then move image from temp to images and input all information from session to the database #echo 'Here is some more debugging info:'; #print_r($_FILES); #print "</pre>"; if ($image_error==TRUE) { switch($image_error_code) { case 1: $error_message='The file you have uploaded is to large. Please upload a file of a smaller size.'; break; case 2: $error_message='The file you have uploaded is to large. Please upload a file of a smaller size.'; break; case 3: $error_message='The file that you uploaded only partially uploaded. Please try to upload this again.'; break; case 4: $error_message='No file has been uploaded. Please check and try again.'; break; case 6: $error_message='Please try to upload the file again. If this problem continues please contact us.'; break; case 7: $error_message='The file type that you have tried to upload is not an image. Please try again. Make sure that your file names end in either .jpg, .png, .gif, .bmp'; break; case 8: $error_message='The image file that you have uploaded is not of a type supported by the website. Please select another file that ends with either .jpg, .png, .bmp, .gif'; break; case 9: $error_message='Please try to upload the file again. If you get the same error message after you upload the file, please rename the file.'; break; case 10: $error_message='There has been an error in uploading your file. Please check the file and try again'; break; } // switch if (!isset($error_message)) { $error_message='The file type that you have tried to upload is not an image. Please try again. Make sure that your file names end in either .jpg, .png, .gif, .bmp';    } $error_message='Error: '.$error_message; $error_upload_form=TRUE;    } } if ($error_upload_form==TRUE) { echo Heading('Place an Advert','Upload a photo of your material.',$TotalSteps,'3'); echo '<br>'; error_message($error_message); echo '<br>'; echo '<form enctype="multipart/form-data" action="'.$place_page.'" name="formMemberRegistration4" id="formMemberRegistration4" method="post" onSubmit="return validateMemberRegistration4()">'; echo '<table width="770" align="center" cellspacing="0" cellpadding="0" border="0"> <tr> <td>Upload your photo. If you have a photo of your material please click on the "browse" button below and then select the photo from you hard drive (256k Max file size). Once you have done this click on the "continue" button. Please note that if you do not have a photo just click on the "next" button.</td> </tr> <tr> <td>&nbsp;</td> </tr> <tr> <td><input type="hidden" name="MAX_FILE_SIZE" value="'.FILE_UPLOAD_VALUE.'"></td> </tr> <tr> <td align="center">&nbsp;<input name="userfile" size="60" type="file"></td> </tr> <tr> <td>&nbsp;</td> </tr> <tr> <td align="right"><input type="submit" name="page4" value="Next &gt;"></td> </tr> </table> </form>'; } else { $show=TRUE; //no error so this will be the confirm order section #echo 'The finished name is '.$finished_name; if ($show==TRUE) { if (isset($finished_name)) { $_SESSION['image_name']=$finished_name; $_SESSION['filetype']=$filetype; } if (isset($_SESSION['image_name'])) { $size=getimagesize('tmp/'.$_SESSION['image_name'].$_SESSION['filetype']); $pos1=strpos($size[3],'"'); $pos1=$pos1+1; $pos2=strpos($size[3],'"',$pos1); $poswidth=$pos2-$pos1; $width=substr($size[3], $pos1, $poswidth); $pos3=strpos($size[3],'"',$pos2+2); $pos3=$pos3+1; $pos4=strpos($size[3],'"',$pos3); $poswidth=$pos4-$pos3; $height=substr($size[3], $pos3, $poswidth); #echo '<br>The height is '.$height.'<br>'; $image_size=display_image(510,360,$width,$height ); #echo '<pre>'; #echo var_dump($image_size); #echo var_dump($size); #echo '</pre>'; } } } ?>[/code] MOD EDIT: Use code tags
  3. right now i see what you are doing. $rows=count($student_records); $i=0; while ($i<$rows) { $student_records[$i]; $i++ } however instead of this why don't you just put your bit of code below where you currently are trying to echo the student records. You do not have to pull details from the database at the top of the page. I assumed you must have wanted it there for some reason and then was going to use it again. while($row = mysql_fetch_array($result)){ $id = $row['id']; $name = $row['name']; $father_name = $row['father_name']; $gender = $row['gender']; $address = $row['address']; echo "<tr><td>$id</td><td>$name</td><td>$father_name</td><td>$gender</td><td>$address</td></tr>"; } echo "</table></form>"; }
  4. can't really say that I do get you. Can't see the problem perhaps its just me. If you want to use the data more than once you could put it in an array $i=0; while($row = mysql_fetch_array($result)){ $id = $row['id']; $name = $row['name']; $father_name = $row['father_name']; $gender = $row['gender']; $address = $row['address']; $tableRow[$i]="<tr><td>$id</td><td>$name</td><td>$father_name</td><td>$gender</td><td>$address</td></tr>";         $i++; } then you could use this to uput again where you want. From what you have above I still don't see why you would need to to this. Sorry.
  5. Does the file upload? Just want to get an idea of where it is failing Also although silly I will ask that your not using a windows server?
  6. why not just retrieve the data then below the header and display it there? Don't really understand what you are trying to get at here? perhpas if you can elaberate a bit more and if there is a problem with the code clean it up a bit so it is quicker to look through
  7. don't see any code above at all to upload a file. Where is the code for this part
  8. ops yea  right, must start to take more notice of what people are asking.
  9. Well not sure 100% the best way of doing this. Perhaps have a javascript timer that will activate a link for a transparent frame with a url for the user id in handling script or use a $_SESSION user id for a more secure system, this will direct to a script that will collect the get and query the database to see if a message has been set in the database if it has it will pull the information and update the messenger again using javascript. I think either way this will be about 80% javascript and 20% php.
  10. mysql_query("INSERT INTO CUSTOMER (Company, `First Name`, `Last Name`, Event, price) VALUES ('$Company', '$first', '$last', '$event', '$price')"); mysql_close(); you have quoted around the table field names, only quote the values. if you have the following after your query  it will show what the problem is.    or die(mysql_error());
  11. you could do this function smileys() { $ex='<br>some html<br>; return $ex; } echo smileys; or function smileys() { echo '<br>some html<br>; } If you use the second method it can cause problems when out putting to tables etc. Sometimes it does some strange stuff.
  12. Have a look at the ajax forum: http://www.phpfreaks.com/forums/index.php/board,51.0.html
  13. There could be all sorts of reasons why a script will run on one server and not the other. The first thing you should do is go into you php.ini file and sell all errors and warnings to on. This will then show your errors in the script. Fix them and it should work on the other server. If one server is windows for example that is a different story. If also they are different versions of php that can also cause another problem. Also if you script uses global varibles this can be a problem. Your script should be getting varibles from the url by using the $_GET and from forms $_POST.
  14. Would think you are going to need to get the hang of javascript for this, sounds like a job for ajax
  15. sorry misread the first post. Thought you wanted to put it into a database. If you are only getting the value out ignore what I have said above. Perhaps you can put it to a $_SESSION value. Rewriting this everytime would be as bad as the database thing above, (don't know where I got the idea you wanted to do that). Anyway you still need Ajax
  16. I would have thought that with both onkeyup and onchange that every time the user types another letter it will query the database using ajax. I think it will be a hard thing to do without making the server do extra work, unless the user is typing in something that is the same length then you could check if after the user gets above that lenght. If you think about it how will the form know when the user is getting to the end of what they are typing it will have to enter in the database every time they press a key. If you use the onblur method the user will still have to click else where on the form or press the tab. I think what you are trying to do isn't really possible. I would like to hear if you do manage to do it and how you have gone about it. Good luck
  17. They do but remember if you are going to echo or print javascript you will need to escape the quotes \'
  18. As this is users also add some javascript to disable the submit button once pressed. You still should do all the server side as well it just helps a little and if the site is running slow the user feels like something is happening
  19. If it is before you can submit it then you need Javascript. Have you forgoten what language you used.
  20. $qry  =mysql_query("SELECT * FROM `staff` WHERE `clue` > 0") or die(msyql_error()); echo mysql_num_rows($qry); This should help you get the mysql error
  21. if you want the script to run its self and generate the new code you need crontab
  22. if you mean for form validation then what you need to do is start the forms with values that are null and ERROR=FALSE. then after a form is submitted run through it and check for errors then return ie ERROR=TRUE if there is an error. Here you will get the values from your post information and then set the values in the form as these.
  23. If the main program is asp it would be a windows server. Look into any code that will use $_SERVER varibles. Some work some don't.
  24. my god, this doesn't sound good. This must be on a windows server. Some $_SERVER varibles don't work so if you are setting any url links based on these have a look.
  25. don't see why it would be taking along time. looks ok to me. I take it you only have 10 records in the table as there is no where clause in the query. You say that sometimes it doesn't work, what is the error you get
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.