Jump to content

mstabosz

Members
  • Posts

    13
  • Joined

  • Last visited

mstabosz's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. That got it. Thanks. I meant to tell you on Friday evening but got caught up in other things. It looks like it's working, except now I get this message. Warning: Cannot modify header information - headers already sent by (output started at D:\Hosting\8734914\html\geoquitties\uploadpage.php:227) in D:\Hosting\8734914\html\geoquitties\uploader.inc on line 63 Which was probably caused by this: if($fileUploadSuccess) { echo '<p class="informationmessage">"File ' .$fileName .' uploaded successfully"</p>'; header('Refresh: 5;url=uploadpage.php?trimslash=YES'); } else echo "<p class=\"errormessage\">Problem uploading file $fileName!</p>"; Which is probably due to that thing I read about how you're not supposed to add headers after output has echoed to the screen. I threw in some output buffering and it seems to work okay now. I was using headers like that to redirect the page in about a dozen different places. My dev machine didn't seem to mind but the remote server is much more strict. Looks like I've got a fair bit of testing to do. :Q Oh well. Thanks a bunch for your help.
  2. So you're saying I should do this at line 55 where I move the uploaded file? //Set file permissions. chmod($currentDir,755); //Move uploaded file from temp directory to permanent location. $fileUploadSuccess = move_uploaded_file($_FILES[$upName]['tmp_name'], "$currentDir/$fileName"); Tried that, got Warning: chmod() [function.chmod]: Permission denied in D:\Hosting\8734914\html\geoquitties\uploader.inc on line 55 followed by the same errors as before.
  3. So this might be a problem that I have to take up with my hosting provider, but maybe you guys can help me through it. I wrote this web site called Geoquitties. It's sorta like the old Geocities... you sign up for an account, then you get a folder that you can upload files to. You can also create new directories. I'm not trying to, like, commercialize this or anything. I made it as a project for school and also as a thing I can show off. So I wrote all this on my personal computer, which is running XAMPP 3.1.0. It all worked just fine Then I tried to upload it to my GoDaddy account. Now I get this when I try to upload files there: Warning: move_uploaded_file(./mstabosz/csb.log) [function.move-uploaded-file]: failed to open stream: Permission denied in D:\Hosting\8734914\html\geoquitties\uploader.inc on line 55 Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'D:\Temp\php\phpA592.tmp' to './mstabosz/csb.log' in D:\Hosting\8734914\html\geoquitties\uploader.inc on line 55 I guess it's spitting out those error messages because I didn't do a lot of error checking in my own code, so it gives the PHP default stuff. I'm not sure what code to post because the code, I think, is okay, and there's kind of a lot of probably irrelevant code. Here's the code for the form that makes the uploader blocks and moves the files. //Use the session variable if available. //Use the default value of 5 if not. if(isset($_SESSION['blocks'])) $blocks = $_SESSION['blocks']; else $blocks = 5; //Create a new block of uploaders. $uploaders = new uploaderChunk($blocks); //The name of a particular upload field. $uploaderName; //Upload any files available. for($i = 1; $i <= $blocks; $i++) { $uploaderName = "uploader" .$i; if(!empty($_FILES[$uploaderName]['name'])) $uploaders->moveFiles($uploaderName); } and here's the uploader.inc class it refers to. Line 55 reads: $fileUploadSuccess = move_uploaded_file($_FILES[$upName]['tmp_name'], "$currentDir/$fileName"); <?php class uploaderChunk { private $classUploaderName; private $numBlocks; public function __construct($blocks) { //Start off the uploader form. echo <<<FORMSTART <div id="uploaderchunk" class="formbox"> <form action="uploadpage.php" method="post" enctype="multipart/form-data"> <input type="hidden" name="MAX_FILE_SIZE" value="30000" /> FORMSTART; //Set up a count of the number of blocks in the chunk. $this->numBlocks = $blocks; //Make the uploader blocks. for($i = 1; $i <= $this->numBlocks; $i++) { $this->classUploaderName = "uploader" .$i; $this->makeUploaderBlock(); } //Build the submit button for the chunk. echo '<input type="submit" name="uploadButton" value="Upload now!" />'; //Close out the uploader form. echo "\n</form>"; echo "\n</div>"; } private function makeUploaderBlock() { echo <<<UPLOADERBLOCK <div class="uploader"> <input type = "file" name="$this->classUploaderName" /> </div> UPLOADERBLOCK; } public function moveFiles($upName) { //The currently logged on user. $currentDir = $_SESSION['currentDirectory']; //Boolean to tell if the file uploaded successfully. $fileUploadSuccess = FALSE; //A file box was not empty. if(!empty($_FILES[$upName]['name'])) { //Get the name of the file in the current uploader box. $fileName = $_FILES[$upName]['name']; //Move uploaded file from temp directory to permanent location. $fileUploadSuccess = move_uploaded_file($_FILES[$upName]['tmp_name'], "$currentDir/$fileName"); print "<br>Results: " .$_FILES[$upName]['error']; if($fileUploadSuccess) { $this->showAlertMessage("File $fileName uploaded successfully"); header('Refresh: 5;url=uploadpage.php?trimslash=YES'); } else echo "<p class=\"errormessage\">Problem uploading file $fileName!</p>"; } } } //End of uploaderChunk class. ?> Again I'm not sure if that's relevant because the code works okay on my development machine. Is there anything I can add that will make it work when I upload it? Or should I contact Godaddy support? I'm not sure how to approach this.
  4. I have a theoretical question. I noticed that there is a strcmp() function in PHP for comparing strings. You can also put strings inside switch statements and use the == operator for comparison. Given that, is there a difference between using strcmp() to find if strings are equal versus just using the == operator? I know that in Java, use of == is unreliable because of the nature of the way that language handles strings. So in Java you use String.equals(), String.compareTo(), or String.compareToIgnoreCase(). Is that the case in PHP? Is any approach to comparing strings better than the other in any way?
  5. Thanks requinix. That worked out great! Thanks to you too Irate. Although I didn't try your solution, I appreciate the help.
  6. I thought this would be straightforward, but I'm missing something. Here are the rules: 3 to 20 characters. Letters either upper or lower case are allowed. Numbers are allowed. Nothing else is allowed. So jsmith is okay, as is jsmith123, but jsmith! is FORBIDDEN. So using what I know about regular expressions and a regular expressions tester at http://regexpal.com/, I came up with this: [a-zA-Z0-9]{3,20} That allows jsmith and jsmith123, which is good, but it also allows jsmith!, which is bad. The regex tester highlights the allowed characters in all instances and leaves the exclamation point alone. But what I want is an all or nothing thing. If that ! gets in there, throw away the rest of the expression. I have a feeling I'm misunderstanding something about regular expressions.
  7. Thanks for the explanation kicken. And thanks for the troubleshooting tip Ch0cu3r.. I have a feeling that my Javascript may not have been working because of some miniscule syntax error somewhere, like a character where it shouldn't be or a missing semicolon or something. One of those little details that is so maddening because it's so hard to detect.
  8. For equally baffling reasons, this seems to have started working with no additional modifications on my part. RRRRRRRRRRRRRRRRRRGGGGGGGGGGGHHHH........ Thanks for your tip. I'll keep that in mind for the future. I think I've heard this but don't get why. If nothing is accessing the session variables, why should it matter that the session hasn't been started?
  9. Been beating my head against the wall on this and can't figure it out. I thought I had the syntax down, and I can't see anything wrong with it. So I have a web page which uses PHP to allow you to create a new folder on the server. It's a text box, with a submit button next to it. You type in your folder name and PHP creates the folder if it does not already exist. That part works. I'm trying to slip in some JavaScript to do input validation. The problem is that I can't seem to make the JavaScript piece run, at all. I'm just trying to make the basic connection before doing the actual validation coding, so my JavaScript is nothing but a single function with an alert inside it right now. Here's my JavaScript, entitled simpl function validateNewDir() { alert("HI THERE"); } Here's my PHP script. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>New directory page</title> <script src="javascript/validationScript.js"></script> </head> <?php session_start(); if(isset($_POST['makeDir'])) { //Flag variable to indicate that a folder already exists. $folderExists = FALSE; //Get the current directory. $currentDir = $_SESSION['currentDirectory']; //First make a list of everything in this folder. $allfiles = scandir($currentDir); //Array to hold just the folder names. $folders = array(); //Look through, move only the directories to a secondary array. foreach($allfiles as $thisfile) if(is_dir("$currentDir/$thisfile")) array_push($folders,$thisfile); //Load new directory name into local variable. $newName = $_POST['dirName']; //Compare name to the list of existing directories. foreach($folders as $thisFolder) //If proposed folder name already exists, set flag to indicate such. if(strcasecmp($newName,$thisFolder) == 0) $folderExists = TRUE; //If folder exists, alert user if($folderExists) { echo '<p class="errormessage">Folder <span class="highlight">' .$newName .'</span>'; echo ' already exists! Please choose a new '; echo 'name. Be aware that folder names are <strong>NOT</strong> case sensitive.</p>'; } else { echo '<p class="informationmessage">Folder <span class="highlight">' .$newName .'</span>'; echo ' successfully created!</p>'; mkdir("$currentDir/$newName"); } } echo <<<GETDIRECTORYNAMEBLOCK <div id="directorymaker"> <span>Enter the name of the directory you wish to create: </span> <form action="directorypage.php" method="post"> <input type="text" name="dirName" /> <input type="submit" name="makeDir" value="Create this directory!" id="dirBox" onclick="validateNewDir()"/> </form> <a href="uploadpage.php">Click here to return to the main page.</a> GETDIRECTORYNAMEBLOCK; ?> It's really baffling. I have an almost identical script named "javascriptTest.js" in the same folder. function hi() { alert("Hello!"); } If I alter the last line of the form in my PHP script to say <input type="submit" name="makeDir" value="Create this directory!" id="dirBox" onclick="hi()"/> and add <script src="javascript/javascriptTest.js"></script> in my page's header, THAT works fine. The alert pops up when I hit the submit button. I even ran both scripts through a Javascript emulator at http://writecodeonline.com/javascript/ and both work. What the heck is going on?
  10. Including the enctype resolved this. One question remains. The file input looks different in different browsers. In Internet Explorer and Opera, as well as in the web browser inside Eclipse (which I'm guessing is just Internet Explorer), there's a box like a text box, and the "Browse" button to the right of it. In Firefox, Chrome, and Safari, the "Browse" button is to the left followed by plain text that says "No file selected" until you browse for a file, at which point it is replaced with the file name. I prefer the look of the Internet Explorer/Opera/Eclipse version. Is there any way to make it look that way in the other browsers?
  11. Hi Psycho, thanks for the prompt reply. Regarding point 1, that's it. Probably. I haven't had the chance to modify my code yet. Thanks. I knew that was part of the process, but I just totally forgot to put that in there and I guess I kept overlooking it. Sometimes you just make a dumb mistake and need a fresh pair of eyes to point it out. On the other points, thanks for the insights. You're right, my code is really sloppy. This is the first time I've done object oriented programming in PHP, and a lot of the time when I'm trying something new programming-wise I'll do something of a quick and dirty form just to see if I can get it working, then do a second pass to later to see if I can make it better. Also, I was getting frustrated and trying a lot of random things to try and get it going, so that probably made a bad situation worse.
  12. Hi all, First time poster. I'm a novice at PHP, trying to work it out. Right now I'm trying to write something that is a rough approximation of the old 1990s Geocities site. The goal here is to have a file uploader form with 5 uploaders by default, but the user can add more as he pleases. Most of the form elements are in plain old HTML, but I gotta use PHP to generate the block of the form that has the upload button. I'm trying to do this with classes. At this point, I'm just trying to get the PHP script to acknowledge that it received and uploaded the file. Actually putting it in the right place comes later. Here's what I have so far. I'm sorry it's a little sparse on comments. <div id="uploaderBox"> <form action="uploadpage.php" method="post"> <input type="hidden" name="MAX_FILE_SIZE" value="30000" /> <?php //Create new uploaderBlock object. $myUploader = new uploaderBlock(2); //Should be interpreted as if(isset($_FILES['uploader2'] if(isset($_FILES[$myUploader->getUploaderName()])) $myUploader->getUploadedFile(); else print "Nothing uploaded yet!"; ?> <input type="submit" name="submitButton" value="Upload now!" /> </form> </div> <?php class uploaderBlock { private $uploaderName; public function __construct($upNumber) { $this->uploaderName = "uploader" .$upNumber; $this->makeUploaderBlock(); } public function makeUploaderBlock() { print '<input type="file" name="' .$this->uploaderName .'" />'; print "<br />\n"; } public function getUploadedFile() { print "UPLOADED FILE:<br />"; print $_FILES[$this->uploaderName]; } public function getUploaderName() { return $this->uploaderName; } } ?> The problem is that the script never seems to realize that a file has been uploaded. The if(isset($_FILES[$myUploader->getUploaderName()])) statement always evaluates to FALSE. If I remove the if-else and just run the $myUploader->getUploadedFile(); statement, I get the error Notice: Undefined index: uploader2 in C:\Dropbox\xampp\htdocs\projects\FinalProject\uploadpage.php on line 43 It's funny because I thought I understood this. Last week I did this little test script which works fine. I can't figure out what I'm doing differently. I mean, in the earlier script I'm using pure HTML for the entire form, and no objects. <form action="file_io_test.php" enctype="multipart/form-data" method="post"> <input type="hidden" name="MAX_FILE_SIZE" value="30000" /> <input type="file" name="uploader1" /><br /> <input type="submit" name="submitbutton" value="Upload!" /> </form> <?php $infile = "stuff.txt"; $uploader = 'uploader1'; if(isset($_FILES[$uploader]['name'])) { $fileName = $_FILES[$uploader]['name']; move_uploaded_file($_FILES[$uploader]['tmp_name'], 'uploads/' .$fileName); } else print "Nothing uploaded yet!"; ?>
×
×
  • 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.