Jump to content

graphxsman

Members
  • Posts

    11
  • Joined

  • Last visited

graphxsman's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thanks so much, Sleepy Member!! It is working beautifully! ~graphxsman
  2. Thanks for looking at my problem. First of all, I am a new comer to PHP, so if you get frustrated quickly with assisting someone, please don't trouble yourself with helping me. I'm saying this as nice as text can express it . Like all of us, learning something new takes time and a few "stupid" questions are in order. I have attempted to incorporate many tips and suggestions from other php coders, but I am still having quite the time getting my code to work. Here is the background for my project: I am designing a web page (career.html) and I want to include a simple upload link on it so that people can upload their resumé and their cover letter to the server, but I'd really like to have it sent directly to HR's email. But for now, I'd just lie to get a grasp on the upload issue. Here is the FORM code: <form action="upload9.php" method="post" enctype="multipart/form-data"> <div id="upload"><input type="file" name="file" /></div> <div id="submit"><input type="submit" value="Upload" /></div> </form> This is embedded in the body of the career.html. I worked through some php tutorial stuff from Wc3 tutorials and found this php upload code, which I am trying to use: <!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"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Upload 9</title> </head> <body> <?php ini_set('display_errors', 1); error_reporting(E_ALL); $allowedExts = array("doc", "pdf", "dotx", "rtf", "txt"); $temp = explode(".", $_FILES["file"]["name"]); $extension = end($temp); if ((($_FILES["file"]["type"] == "doc") || ($_FILES["file"]["type"] == "pdf") || ($_FILES["file"]["type"] == "dotx") || ($_FILES["file"]["type"] == "rtf") || ($_FILES["file"]["type"] == "txt")) && ($_FILES["file"]["size"] < 5242880) && in_array($extension, $allowedExts)) { if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br>"; } else { echo "Upload: " . $_FILES["file"]["name"] . "<br>"; echo "Type: " . $_FILES["file"]["type"] . "<br>"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>"; echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br>"; if (file_exists("uploads/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "uploads/" . $_FILES["file"]["name"]); echo "Stored in: " . "uploads/" . $_FILES["file"]["name"]; } } } else { echo "Invalid file."; } ?> </body> </html> I added this ini_set('display_errors', 1); error_reporting(E_ALL); code as per a php developer's suggestion for error checking, but all I get when I run this code is "Invalid file." PHP 5.3 is installed on the server. I have the "career.html", the "upload9.php" and the "uploads" folder all in the same directory. I can not get a file to upload to the "uploads" folder and I just get the "Invalid file" echo. If anyone would be willing to help me, I would be very grateful. Thank you.
  3. Hmm, well, I don't understand that string of info, either. I just tested the upload link by linking to a random file (Week-10_8_13.dotx) on my computer and trying to upload it. What you see is the echo I got.
  4. Thanks so much, mac_gyver. I appreciate your assistance. I'm really new at this php stuff. Scripting languages have been a rough thing for me to grasp. Since I'm new at this, I'm finding some of your instructions assume a bit more knowledge of php than I have. So if you find helping me frustrating, don't feel obligated. I'll get through this in time. I always do. Like Javascript, I am assuming the code runs in a hierarchical manner from what I grasp in your instructions. So I put the code you sent in the following place: <?php echo "<pre>"; echo "FILES:"; print_r($_FILES); echo "</pre>"; // $allowedExts = array("doc", "pdf", "dotx", "rtf", "txt"); $temp = explode(".", $_FILES["file"]["name"]); $extension = end($temp); if ((($_FILES["file"]["type"] == "text/doc") || ($_FILES["file"]["type"] == "text/pdf") || ($_FILES["file"]["type"] == "text/dotx") || ($_FILES["file"]["type"] == "text/rtf") || ($_FILES["file"]["type"] == "text/txt")) && ($_FILES["file"]["size"] < 5242880) && in_array($extension, $allowedExts)) { if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br>"; } else { echo "Upload: " . $_FILES["file"]["name"] . "<br>"; echo "Type: " . $_FILES["file"]["type"] . "<br>"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>"; echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br>"; if (file_exists("uploads/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "uploads/" . $_FILES["file"]["name"]); echo "Stored in: " . "uploads/" . $_FILES["file"]["name"]; } } } else { echo "Invalid file."; } ?> But I got this message: FILES:Array ( [file] => Array ( [name] => Week-10_8_13.dotx [type] => application/vnd.openxmlformats-officedocument.wordprocessingml.template [tmp_name] => /tmp/php5cWfFQ [error] => 0 => 88652 ) ) Invalid file. Correcting the logic in my code is the problem I'm having. I'm not knowledgable enough to know what logic isn't correct or even how to code it. I'm trying to find something on the web and then tweak it to fit my needs. Maybe I should go with a jquery or javascript method instead.
  5. Well, if I may indulge anybody's expertise once again I'd be much obliged. I really want to have a multiple file upload, but I just can't seem to get anything to "work." So for now I'm trying to wrap my brain around a simple single file upload. I'm not sure why i'm having such a difficult time with this. Maybe it's a matter of not having my files set up right. So here's what I have to test a working arrangement. I have a html document named "careers.html" that I have put the following form in for the upload link: FORM: <form action="upload9.php" method="post" enctype="multipart/form-data"> <input type="file" id="file" name="file" /> <input type="submit" value="Upload" /> </form> Here is the the php upload doc, "upload9.php", that the "action" is being called to: PHP: <?php $allowedExts = array("doc", "pdf", "dotx", "rtf", "txt"); $temp = explode(".", $_FILES["file"]["name"]); $extension = end($temp); if ((($_FILES["file"]["type"] == "text/doc") || ($_FILES["file"]["type"] == "text/pdf") || ($_FILES["file"]["type"] == "text/dotx") || ($_FILES["file"]["type"] == "text/rtf") || ($_FILES["file"]["type"] == "text/txt")) && ($_FILES["file"]["size"] < 5242880) && in_array($extension, $allowedExts)) { if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br>"; } else { echo "Upload: " . $_FILES["file"]["name"] . "<br>"; echo "Type: " . $_FILES["file"]["type"] . "<br>"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>"; echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br>"; if (file_exists("uploads/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "uploads/" . $_FILES["file"]["name"]); echo "Stored in: " . "uploads/" . $_FILES["file"]["name"]; } } } else { echo "Invalid file."; } ?> I have the php, the html and the "uploads" folder in the same directory on my web server. When I run the code above, I get the error message "Invalid File." No matter what file type I link to. Incorrect or correct. I looked at the resources you all sent and I tried a few of them, but I just can't seem to get anything to show up in my "uploads" folder on my server or to get any of the scripts to "work." I just want to get something to work and then, as I said, I'd like to make the html form and php actually function as a multiple file upload, or really, be able to send the file to an email address without going to the server. But first I've got to get something to work for me. If anybody can assist me, that would be great. Sorry I'm not grasping this too well, although I am slowly seeing how things work.
  6. Wow, well, thanks to all. All this new info certainly gives me something to do. I'll have to digest what you've told me and see if I can understand it and apply it. Thanks again!
  7. Thanks for that piece of code, mac_gyver. I applied it right away. I'm getting this echo now, though. "The file extension you supplied is: , the allowable types are: pdf, doc, dotx, rtf, txt" I get this echo whether I try to upload a pdf (an allowed ext.) or a png (not allowed ext.). It's fun that it's working, though. :-)
  8. Thanks for the tip mac_gyver. That is good advice, unfortunately, being a newbie at php, I'm not sure what more code I can add to echo those trouble shooting statements, but I bet I can find that info somewhere.
  9. Thanks so much, Ch0cu3r. It's definitely working now, but for some reason I'm now getting the echo, "Invalid file type" even if I upload the correct file type. I thought perhaps not having all the 'file' s correctly labeled might be doing that, but even after changing them to 'myfile' it still gives me the echo. Here's the code with my tweaks. Hopefully I didn't mess anything up. I did have to tweak some of the syntax because it was saying it was incorrect. <?php $uploaddir = "uploads/"; $allowed_ext = array('pdf', 'doc', 'dotx', 'rtf', 'txt'); $max_size = "5242880"; $extension = pathinfo($_FILES['myfile']['name'], PATHINFO_EXTENSION); // get the file extension changed to myfile // check if extension is in the allowed extensions array if(in_array($extension, $allowed_ext)) { // uploaded file has valid file extension // check file size if($_FILES['myfile']['size'] > $max_size) { echo "File is too big."; } // file size ok else { // move uploaded to storage location if (move_upload_file($_FILES['myfile']['tmp_name'],$uploaddir.'/'.$_FILES['myfile']['name'])) // changed to myfile { echo "Your file has been uploaded successfully."; } else { echo "Sorry, something went wrong."; } } } // file extension not allowed else { echo "Invalid file type."; } ?>
  10. Thanks for tips! It seems to be working now, but there appears to be something wrong with the php code. I keep getting the echo "File is too big." I should only get that IF the file is too big, but no matter how small of a file I choose, it gives that echo. I'd like simple code that restricts file size and extension mostly.
  11. Hi, I'm trying to incorporate a very simple php upload file link script into my website, but it doesn't seem to be running correctly. I'm using a very simple html form set up to activate the script. I know I have the correct coding and syntax set up because I'm using an already coded script from a php developer. My inquiry has to do with folder and file placement on the root directory. I have php 5.3 installed on the server. Does the php file and the html file that runs the code have to be in a special folder other than the public_html folder or can it be amongst the other site files? I know there needs to be an "upload" folder to place the uploaded files, but do the php and html files need to be in that folder too? When I try to run the script, all I get is a blank web page, but the url shows the php file in the address. FORM: <form action="upload.php" method="post" enctype="multipart/form-data"> <input type="file" name="myfile" size="30" /> <input type="file" name="myfile" size="30" /><br/> <input type="submit" value="Upload" /> </form> PHP: <?php $uploaddir = "uploads/"; $allowed_ext = "pdf, doc, dotx"; $max_size = "20000"; $extension = pathinfo($_FILES['file']['name']); $extension = $extension[extension]; $allowed_paths = explode(", ", $allowed_ext); for ($i = 0; $i < count ($allowed_paths); $i++); { if ($allowed_paths[$i] == "$extension"); { $ok = "1"; } if ($ok == "1") { if($_FILES['myfile']['size'] > $max_size); } echo "File is too big."; exit; } if (is_upload_file($_FILES['myfile']['tmp_name'])) { move_upload_file($_FILES['myfile']['tmp_name'],$uploaddir.'/'.$_FILES['file']['name']); echo "Your file has been uploaded successfully."; } else { echo "Incorrect file extension."; } ?> Thanks!
×
×
  • 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.