gordon.c Posted January 19, 2008 Share Posted January 19, 2008 Hello I have come to a problem when I need to get some files on the web server using php... I have used some functions that opened the save/load dialog but never worked Can you please post the code I need for this? Or to post a link where is this being described? Thank you in advance Quote Link to comment https://forums.phpfreaks.com/topic/86824-solved-send-files-on-the-server/ Share on other sites More sharing options...
Ninjakreborn Posted January 19, 2008 Share Posted January 19, 2008 You mean file handling. Google "File handling tutorial". Basically you need * A form for them to be able to submit the files * The error validation (check make sure the file has the right extension, or whatever else you want to verify). * The processor You are going to need to process the file in multiple ways. There are 2 steps. It's transition to temporary data, then from there over to actual server hard disk space. The temporary is generally done on it's on. Depending if you have the ini options set properly. If they are then you are just able to take the file and use PHP's various built in file handling functions. Google "PHP File Handling Functions" to get multiple references related to file handling. For another resource you can also visit www.w3schools.com and choose "PHP" on the left side navigation. Once there you can navigate to the information pages and on the left hand side you will see information about filehandling. Go there for full reference listings as well tutorial examples. Another option would be to google "PHP File Handling Classes" if you know some about object oriented programming, and want to slim down the process of learning file handling (or if your in a hurry). Quote Link to comment https://forums.phpfreaks.com/topic/86824-solved-send-files-on-the-server/#findComment-443753 Share on other sites More sharing options...
pkSML Posted January 20, 2008 Share Posted January 20, 2008 Many results here: http://pksml.net/search/PHP+file+upload+tutorial Quote Link to comment https://forums.phpfreaks.com/topic/86824-solved-send-files-on-the-server/#findComment-443954 Share on other sites More sharing options...
gordon.c Posted January 21, 2008 Author Share Posted January 21, 2008 Hi The codes are pretty much the same so there is not much to do wrong... Still My uploader fails to work. <form method="post"> <input type="file" name="filething" /> <input type="submit valie="go"> <?php //Setting the preliminary variables. $dirThing = "uploads/files/"; //Where the file is to be copied to. $actZip = $_POST['filething']; //Leave this. Gets the file from the HTML page. $finZip = $dirThing.$actZip; //Leave this. //If successfuly uploaded, give happy message. Otherwise, error the guy. Or gal. if(copy($actZip, $finZip)) { //Successful echo 'File Uploaded Successfully'; } //Error else { echo 'Error uploading file. Please try again'; } //End of script. ?> </form> By the way this code is from http://www.apdz.com/phpbb/viewtopic.php?t=165&sid=. Maybe I forgot to add something important to the code? Quote Link to comment https://forums.phpfreaks.com/topic/86824-solved-send-files-on-the-server/#findComment-444926 Share on other sites More sharing options...
GingerRobot Posted January 21, 2008 Share Posted January 21, 2008 Im afriad your code isn't really anything like the examples given. Some of the things missing: 1.) You need to specify an ENCTYPE of "multipart/form-data" in the form tag 2.) You need a form field called MAX_FILE_SIZE 3.) The information regarding files is contained in the $_FILES superglobal, not $_POST See: http://uk2.php.net/manual/en/features.file-upload.php for an example form and example php. Quote Link to comment https://forums.phpfreaks.com/topic/86824-solved-send-files-on-the-server/#findComment-444955 Share on other sites More sharing options...
gordon.c Posted January 21, 2008 Author Share Posted January 21, 2008 Sorry still dont get the sollution <!-- The data encoding type, enctype, MUST be specified as below --> <form enctype="multipart/form-data" method="POST"> <!-- MAX_FILE_SIZE must precede the file input field --> <input type="hidden" name="MAX_FILE_SIZE" value="30000" /> <!-- Name of input element determines name in $_FILES array --> Send this file: <input name="userfile" type="file" /> <input type="submit" name='send' value="Send File" /> </form> <?php if($_GET['send']) { // In PHP versions earlier than 4.1.0, $HTTP_POST_FILES should be used instead // of $_FILES. $uploaddir = 'http://funbox.wz.cz/'; $uploadfile = $uploaddir . basename($_FILES['userfile']['name']); 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"; } echo 'Here is some more debugging info:'; print_r($_FILES); print "</pre>"; } ?> What is wrong with this code? Quote Link to comment https://forums.phpfreaks.com/topic/86824-solved-send-files-on-the-server/#findComment-445151 Share on other sites More sharing options...
adam291086 Posted January 21, 2008 Share Posted January 21, 2008 add error_reporting(E_ALL); at the top of your script and post any errors along with the line of code that error is on Quote Link to comment https://forums.phpfreaks.com/topic/86824-solved-send-files-on-the-server/#findComment-445163 Share on other sites More sharing options...
gordon.c Posted January 21, 2008 Author Share Posted January 21, 2008 add error_reporting(E_ALL); at the top of your script and post any errors along with the line of code that error is on Warning: Undefined index: send in c:\apache\htdocs\upload.php on line 12 This warning it shows before and even after the send... Quote Link to comment https://forums.phpfreaks.com/topic/86824-solved-send-files-on-the-server/#findComment-445304 Share on other sites More sharing options...
john010117 Posted January 21, 2008 Share Posted January 21, 2008 Put: if(isset($_POST['send'])) in place of if($_GET['send']) Quote Link to comment https://forums.phpfreaks.com/topic/86824-solved-send-files-on-the-server/#findComment-445326 Share on other sites More sharing options...
pkSML Posted January 22, 2008 Share Posted January 22, 2008 $uploaddir = 'http://funbox.wz.cz/'; You need to save the file locally with the filesystem. You can't save a file to a URL. Quote Link to comment https://forums.phpfreaks.com/topic/86824-solved-send-files-on-the-server/#findComment-445735 Share on other sites More sharing options...
gordon.c Posted January 22, 2008 Author Share Posted January 22, 2008 This works better thanks for that... if(isset($_POST['send'])) About the uploading path... Where should I upload it in terms of 'http://funbox.wz.cz/' ? Quote Link to comment https://forums.phpfreaks.com/topic/86824-solved-send-files-on-the-server/#findComment-446111 Share on other sites More sharing options...
gordon.c Posted January 22, 2008 Author Share Posted January 22, 2008 Problem solved... found the right code thx everyone for help Quote Link to comment https://forums.phpfreaks.com/topic/86824-solved-send-files-on-the-server/#findComment-446187 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.