Jump to content

[SOLVED] Send files on the server


Recommended Posts



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

Link to comment
Share on other sites

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).

Link to comment
Share on other sites



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)) {
  echo 'File Uploaded Successfully';
else {
  echo 'Error uploading file. Please try again';

//End of script. ?>


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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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" />

// 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 "</pre>";

What is wrong with this code?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • 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.