Jump to content

Fukushousha

Members
  • Posts

    89
  • Joined

  • Last visited

Everything posted by Fukushousha

  1. Ho! That worked very nice. Deirdre's dad that is what I did. Just stored it in xml so I could edit it easily and have some form of knowledge database, since the forms represent knowledge.My problem was solved by justsomeguy's very simple remark. I had no idea that <form ..... action="" .... > equals <form ..... action="<?php $_SERVER['PHP_SELF']?>" .... > . What I wanted to do worked now. Thanks!
  2. Yeah I know it is server side but I thought that it could work like that. Hm ... can anyone think of a workaround for this? Any way to both dynamically create the forms and be able to call the whole php script again whenever the php submit button is pressed?
  3. Hello all.I have a problem. Up to now the calls to $_SERVER['PHP_SELF'] worked like a charm in any form in my website. Now I made something like ... a dynamic form generation. I am making the various forms by use of Javascript.LAter the javascript function is called inside a php script. Example of .js script: function fillSetArt(div){ //we load the XML file into xmlAudioObj xmlArtObj = loadXML(xmlArtObj,'artsoft.xml'); //this will be the function which will read the file and extract the data we need! xmlArtObj.onreadystatechange = function() { var text = '<form name="userSkills" id="userSkills" action="<?php echo $_SERVER[PHP_SELF]; ?>" method="POST">'; I added the form's declaration and well .. everything inside a javascript script which edits the inner html attribute of the DIV which I want to contain the various forms. The problem is that when I do it this way I get :Access forbidden!You don't have permission to access the requested object. It is either read-protected or not readable by the server.If you think this is a server error, please contact the webmaster.Error 403localhost06/18/08 11:23:07Apache/2.2.8 (Win32) DAV/2 mod_ssl/2.2.8 OpenSSL/0.9.8g mod_autoindex_color PHP/5.2.5And in the browser I can see that the error is thrown due to the PHPSELF call. Any idea how to get around this error?
  4. Yeah I know the $_FILES['file']['type'] but I was reluctant to use it because of the post I linked by someguy in my post above. Anyway I will figure something out. Thanks for the advice people
  5. I used this method because that is what I understood from this post by someguy.And yes I do realize there are too many formats out there >_< It would be 100% simple to tell them I accept only these 3 and that's that. Would that be bad? I am tempted to do so.
  6. Hello,A really quick question to which I just can't find the answer. Basically with my fetch user image I get the image type from the DB (which is stored by looking at the extension) and then give out the appropriate header like that : switch($imagetype){ case ".jpg": header("content-type: image/jpeg"); break; case ".gif": header("content-type: image/gif"); break; case ".png": header("content-type: image/png"); break; default: die("Something is really wrong if you get here.You got no imagetype from the DB");} My question is .. okay ... but what for all other image formats. I actually had forgotten them because I saw only these 3 headers. What should I do with all the other image types?
  7. Sorry for re-bumping my post but I finally managed to solve it. I would like to include the solution in this post since other people might find themselves in my situation. So ... here goes:I tried running the form standalone to see if $_FILES got written. It actually did!So the problem was code-related and not configuration. In my code another php script was included. It was login.php.Login.php contained 2 more forms. As one would expect of a login script ofcourse. I spent the last 2 days searching for empty $_FILES reasons so I learned many different reason why this would happen. One of those was that if you have more forms in the same file with your file upload form you have to add the enctype="multipart/form-data" attribute in them too. I just did that and it works now. So yeah ... ahem ... what can I say? I feel stupid for what I went through the last 2 days to find this. Even installing a different apache/php/mysql bundle .... *sigh*At least now it works. Hope this post can help anyone having the same problem and even help people avoid it in the future.
  8. I am really sorry for bumping my own post but this is ridiculous. I completely uninstalled EasyPhP and saved all of my work in a separate file. I downloaded the XAMPP php/apache/mysql bundle and installed it. Then moved all of my work in the new server, re-made all of my configurations and was good to go.I really thought that it would work. BUT NO! Still ... $_FILES is empty after uploading. I don't know what to do anymore. This was like the last resort ... and it did not work.I am including the whole .php file for which I am talking about ( the one where the user file upload form is ): <?php session_start(); ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/mainSiteTemplate.dwt.php" codeOutsideHTMLIsLocked="false" --><head> <!-- InstanceBeginEditable name="headerstuff" --><title>Settings</title><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><link href="/CSS/mainStyle.css" rel="stylesheet" type="text/css" /><link href="/CSS/profileStyle.css" rel="stylesheet" type="text/css" /><link href="/CSS/settingsStyle.css" rel="stylesheet" type="text/css" /><script type='text/javascript' src='animateScript2.js'></script><!-- InstanceEndEditable --></head><body><div id="pageLogo"></div><div id="pageHead"></div><div id="leftMenu"> <?php//With the page loading we make sure we instantiate a GLOBAL sql connection objectinclude ('sqlConnection.php');global $sql;$sql = new sqlConnection("localhost", "XXXX", "XXXX");include("login.php");displayLogin(); ?></div> <div id="tabMenu"> <ul> <!-- CSS Tabs --><li id="current"><a href="index.php"><span><h1>Home</h1></span></a></li><li><a href="register.php"><span><h1>REGISTER</h1></span></a></li><li><a href='#'><span><h1>USERS</h1></span></a></li><li><a href='#'><span><h1>PROJECTS</h1></span></a></li><li><a href='#'><span><h1>ABOUT</h1></span></a></li> </ul> </div><div id="centerOfPage"><!-- InstanceBeginEditable name="head" --><?phperror_reporting(E_ALL);global $sql;//if no user is logged in then .. do now allow to edit setting ofcourseif(!isset($_SESSION['username'])) echo"You are not logged in. Please log in or register first";else{ //get the user who is logged in now! $username = $_SESSION['username']; $resArray = $sql->selectUser($username); //if the user has not uploaded an image for himself show the default if($resArray['userImage'] == null) { ?> <div id="userImage"> </div> <?php } else {//else .. show the image he uploaded ?> <div id="userImage"> <img src="getUImage.php?usname=<?php echo($username);?>" /> </div> <?php } ?> <div id="imageEdit"> <!--The small form to submit a user image,if it is used refresh the settings page--> <form enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST"> <input type="hidden" name="MAX_FILE_SIZE" value="200000" /> Want to change your picture?<input type="file" name="userpic" id="userpic" /> <input name="subpic" type="submit" value="Upload New Picture" /> </form> <?php eleos();?> </div> <?php}?> <!-- InstanceEndEditable --></div></body><!-- InstanceEnd --></html><?phpfunction eleos(){//if the user clicks the submit picture buttonif(isset($_POST['subpic'])){ //phpinfo(1); print_r($_FILES); }}?> And also the new php.ini part for the file uploading which I ofcourse checked if it is okay. ;;;;;;;;;;;;;;;;; File Uploads;;;;;;;;;;;;;;;;;; Whether to allow HTTP file uploads.file_uploads = On; Temporary directory for HTTP uploaded files (will use system default if not; specified).upload_tmp_dir = "C:\xampp\tmp"; Maximum allowed size for uploaded files.upload_max_filesize = 32M I tried escaping the 2 slashes the tmp dir which would have caused a problem if I typed it as a path. Specifically \t and \x butit did not work. Seems that php must do that automatically when reading where the server's tmp path is.
  9. Quoting from the php manual about headers.
  10. Since it is in another script just save the value of the form script and use a php header to redirect.If your problem is the header syntax then here you can get more info.
  11. Yeah you are right. I should have seen that tab. Anyway, with that gone I still get an error, only this time as you predicted a permission denied one.BIG EDIT:Well ... I was wrong. I was still sleepy and did not write the path correctly. No ... that was not the problem. I can create a file in that directory. So, it can't be because php can't write in the servers tmp directory since it actually can.Damn ... still at point one.
  12. I had tried uploading various sizes of files ... all were "Done" in an instant, even though I am operating on a local server, still it is not normal.BUT I think we might have something with the last thing you said. I just commented everything out from the previous part of code I was working on and put this : if(isset($_POST['subpic'])){ //the temporary file server directory //might use this as a global somewhere later //HAVE TO CHANGE FOR UPLOADING THE SITE IN A WEB SERVER //$tempdir = 'C:\Program Files\EasyPHP 2.0b1\tmp'; //phpinfo(1); file_put_contents("C:\eleos.txt","eleos re paidia");............... This works. No matter where I put it.BUT If I change it to file_put_contents("C:\Program Files\EasyPHP 2.0b1\tmp","eleos re paidia");this is what I get : Warning: file_put_contents(C:\Program Files\EasyPHP 2.0b1 mp) [function.file-put-contents]: failed to open stream: Invalid argument in C:\Program Files\EasyPHP 2.0b1\www\settings.php on line 112 Not to mention nothing is written in the temp folder. That must be it! Php can't write to that file ... but how come I did not get that error warning when I used the file form? Moreover ... how do I overcome this discrepancy? I tried changing the temporary server file from php.ini but nothing happened :/Anyhow it is becoming late here in greece and tomorrow I got SQL exams so I 'd better catch some sleep. Thanks again and will check for replies tomorrow!
  13. Thanks for trying to help justsomeguy. I really appreciate it. Unfortunately thought that wasn't it. My php.ini was already configured like that except from the display_startup_errors setting which was set to off. Even with that set to on though I still get no error.It's as if I never click the file upload button.
  14. Yeah that is what I was saying too. I had similar code, a little more complicated but ... for testing's sake I tried it like that too. Still $_FILES is an empty array.Unfortunately I can't think of anything else. Something must be wrong with my whole installation? I used easyphp to install php, apache and MySQL. But up to now (everything else apart from file uploading) it worked fine!
  15. I will do that with the php.ini thanks for the info!As for the form I can't see what can be wrong with it. I had posted it in the previous topic too. Here it is again: <form enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST"> <input type="hidden" name="MAX_FILE_SIZE" value="200000" /> Want to change your picture?<input type="file" name="userpic" id="userpic" /> <input name="subpic" type="submit" value="Upload" /> </form> All I do somewhere later is check if the subpic is set at the $_POST array and if it is so I am trying to retreive $_FILES['userpic']['name] which returns an undefined index userpic.And the $_FILES array is empty.
  16. Hey all,Since I don't want to bump my other topic and since it already has gone offtopic(not about how to upload images anymore,but about why the heck $_FILES is empty) I decided to create a new topic.So. The problem? I am using a file input form based on the one the php manual shows here. When I am checking the $_FILES array I see it is empty. Actually I got an undefined index, then checked the array and then to my surprise saw it was empty. Then I checked phpinfo() for the variables and all I saw was $_REQUEST['userpic'] and not $_FILES['userpic']. After that I checked php.ini to make sure that file uploading is on. It is. I also checked that my files are not above the file limit. They are not. What can I be doing wrong? I have been trying to understand it the whole day today but to no avail. Any help would be really appreciated.Another quick edit for more info in case it might help to work out this problem. Straight from php.ini ; Whether to allow HTTP file uploads.file_uploads = On; Temporary directory for HTTP uploaded files (will use system default if not; specified).upload_tmp_dir = "C:/Program Files/EasyPHP 2.0b1\tmp\"; Maximum allowed size for uploaded files.upload_max_filesize = 2M Also I tried uploading a 1.80 MB file to see if it would at least delay a little .. but no the new page is loaded immediately. It is just not uploading
  17. Hey mate,If the you are getting the comment from a form all you have to do is add this as the action attribute of the form:action="<?php echo $_SERVER['PHP_SELF']; ?>"Unless I misunderstood your question
  18. Hello there,I am not sure I understand you correctly. But if I understand your problem then a suggestion would be to name the forms in such a way that from the name of the form(or that of the input button) you could instantly extract the name of the entry for which you need to update the points field.
  19. Yeah but the problem lies exactly there. I tried checking to see what the error was but to do so I needed to check inside the $_FILES array. For which I still got an undefined index.Then I tried what you said with print_r to see the contents of the array ... and it is empty. That can only mean that the file is not uploaded. But I can not understand the reason why such a thing would happen.EDIT: As for the file size I had thought to check but still with bigger size limit it doesn't work.
  20. Aha! Thanks again someguy. Imagine ... I was using the link you gave me as a reference but still I used $_FILE instead of $_FILES ... sometimes, you need a second pair of eyes >_<EDIT: Damn guys sorry ... I feel like I am overusing w3schools forum but I really can't find what is wrong here. The past 2 hours I was googling to find the reason why I get an undefined index error but I still don't get it. I understood many other things about the whole proccess but I don't get the undefined index error.So here it is, the code for the form <form enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST"> <input type="hidden" name="MAX_FILE_SIZE" value="6000" /> Want to change your picture?<input name="userpic" type="file" /> <input name="subpic" type="submit" value="Upload New Picture" /> </form> Nothing difficult ... I copied it yesterday when I worked on it and modified from the php manual. Still though I get an undefined index for the $_FILES['userpic']['whateverIneedfromthefilegoeshere'] ....I don't know what to do. I checked php.ini and confirmed that file_uploads are on ... I am using easy php with phpmyadmin. Is this some known glitch it has?Also another question more directed to justsomeguy. You said that I should also check the size of the image(whenever I get past the index error). Isn't this hidden input field supposed to do just that? That is the idea the php manual gave me.
  21. Okay I will do so. Thanks for the tip.One more question (Sorry for the barrage but the whole area has a lot of literature surrounding it)This is the code that executes if the user click the submit picture button of a file input form: //if the user clicks the submit picture buttonif(isset($_POST['subpic'])){ //then let's check the $_FILES array for it and get it $istring = file_get_contents($_FILE['userpic']); //use the real escape string since it is binary data $imageData = mysql_real_escape_string($istring); //then add it to the table $sql->updatetable("users","userImage","'".$imageData."'","username","'".$username."'");} The problem is that the image does not appear at the recall from the Database. I can rule out that the recall from the DB code is correct since I have used it before. The problem must be on the above code. Specifically I am not sure if the file(image) data is saved in the $_FILE['userpic'] assoc array as I used it above. Thanks for the help again!
  22. Hmm I see. Actually I did not figure out how to get the image type. From the DB at least. When I upload it I can do it easily from the $_FILE['name']['type'] assoc array. But when I read it from the DB as a string in order to output it to the user I don't know how to get the type. But since I knew the php script would be used with images I put image/jpeg as the content type and it displayed it (it was saved by me as a .png). Would I have a problem with other image types later if I do it like that? If yes how can I get the image type directly from the DB? The only way I can think of is to save the image type too at upload.
  23. Thanks synook, I will keep that in mind. Thanks for answering :)EDIT: Also if anyone can help with this ... how the heck did you do that up there? With that code? I thought that http headers were used to specify stuff about the data to be sent. You can specify what is about to go trhough so that the browser will know how to "parse" it? Because without the header I get a bunch of gibberish
  24. Thanks a lot synook. That really helped. I was using 150x150 user images and was naive enough to think that a tinyblob would be okay >_<Anyway ... thanks a lot!As for recalling that image from the DB is this the right way? I used my test php file for the testing: /*Already tested ! :)$istring = file_get_contents("css/defaultUImage.png");$sql->updatetable("users","userImage","'".mysql_real_escape_string($istring)."'","username","'Lef'");*//*Now lets see that image*/$arr = $sql->select("SELECT userImage FROM users WHERE username='Lef'");file_put_contents("tempImage.png",$arr['userImage']);?><html><img src="tempImage.png" /></html> It worked ofcourse but I just wanted to check with you guys and see if I am doing this correctly. Again thanks!
  25. Hello friends!My project is proceeding smoothly (or so I want to think) and I am in a very good mood :)This morning I was looking at how I could add images into my users SQL table. Is this what we call a BLOB? In addition how do I add it from php and how do I check an image's size and resize it if need be? I realize I ask a lot of questions in very few lines. There is no need to answer me with a full text if you are bored, just point me to a nice tutorial if it exists since I could not find something
×
×
  • Create New...