How easy upload file with PHP. But I have more problems with autentification this file on server beacuse I'd this file for preview on page
thank you
thank you
| Simulator wrote: |
| Can you post your code, and have you set your folder to 777 |
| landxxx wrote: | ||
I know it's 777 premission who is problem I have any script for my news portal, for upload picturs on news |
| afracsass wrote: | ||||
| hard to grab what you are asking for.
??????????? Please be more specifiec. good luck,
|
| Code: |
| <form enctype="multipart/form-data" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="500000" /> Choose a file to upload: <input name="uploadedfile" type="file" /><br /> <input type="submit" value="Upload File" /> </form> |
| Code: |
| <?php
// Where the file is going to be placed $target_path = "./"; $ufilename = $_FILES['uploadedfile']['name']; /* Add the original filename to our target path. Result is "uploads/filename.extension" */ $uploadfile = $target_path.$ufilename; if($ufilename != ""){ print "<pre>"; if (move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $uploadfile)) { print "File upload succeeded!"; print "Uploaded file information:\n"; print_r($_FILES); } else { print "Upload failed!:\n"; print_r($_FILES); } print "</pre>"; } ?> |
| afracsass wrote: | ||||
| example code for uploading file...
html code
php code
try it and good luck~ |
| mathiaus wrote: |
| Please do not double post |
| Code: |
|
// File Name Issues $name=$_FILES['filef']['name']; $destination = $_SERVER['DOCUMENT_ROOT']."/files/".$_FILES['filef']['name']; $temp_file = $_FILES['filef']['tmp_name']; // Moving Final File move_uploaded_file($temp_file,$destination); |
| Quote: |
|
Warning: move_uploaded_file(/home/mm357/domains/imwcreations.be/public_html/power2009/files/bigsig.jpg): failed to open stream: No such file or directory in /home/mm357/domains/imwcreations.be/public_html/files.php on line 62 Warning: move_uploaded_file(): Unable to move '/tmp/phphgWv76' to '/home/mm357/domains/imwcreations.be/public_html/power2009/files/bigsig.jpg' in /home/mm357/domains/imwcreations.be/public_html/files.php on line 62 |
| Code: |
|
Browse a File to Upload: <i>file must be 1MB or less. (1048576 bytes)</i><br> <input type="file" name="filetoupload"><br> <input type="hidden" name="MAX_FILE_SIZE" value="<?echo $size_bytes; ?>"> <br> <input type="Submit" value="Upload File"> </form> <?php /* Description ----------------------------------------------------- The Super Global Variable $_FILES is used in PHP 4.x.x. $_FILES['upload']['size'] ==> Get the Size of the File in Bytes. $_FILES['upload']['tmp_name'] ==> Returns the Temporary Name of the File. $_FILES['upload']['name'] ==> Returns the Actual Name of the File. $_FILES['upload']['type'] ==> Returns the Type of the File. So if I filetoupload the file 'test.doc', the $_FILES['upload']['name'] would be 'phptut.doc' and $_FILES['upload']['type'] would be 'application/msword'. ---------------------------------------------------------------------*/ // this is the upload dir where files will go. //Don't remove the / //Chmod it (777) $upload_dir = "../"; //change to whatever you want. // files less than 1MB $size_bytes = 1048576; //bytes will be uploaded //check if the directory exist or not. if (!is_dir("$upload_dir")) { die ("The directory <b>($upload_dir)</b> doesn't exist"); } //check if the directory is writable. if (!is_writeable("$upload_dir")){ die ("The directory <b>($upload_dir)</b> is NOT writable, Please Chmod (777)"); } //Check first if a file has been selected //is_filetoupload_file('filename') returns true if //a file was filetoupload via HTTP POST. Returns false otherwise. if (is_uploaded_file($_FILES['filetoupload']['tmp_name'])) { //Get the Size of the File $size = $_FILES['filetoupload']['size']; //Make sure that $size is less than 1MB (1000000 bytes) if ($size > $size_bytes) { echo "File Too Large. Please try again."; exit(); } // $filename will hold the value of the file name submetted from the form. $filename = $_FILES['filetoupload']['name']; // Check if file is Already EXISTS. if(file_exists($upload_dir.$filename)){ echo "Oops! The file named <b>$filename </b>already exists"; exit(); } //Move the File to the Directory of your choice //move_filetoupload_file('filename','destination') Moves an filetoupload file to a new location. if (move_uploaded_file($_FILES['filetoupload']['tmp_name'],$upload_dir.$filename)) { //tell the user that the file has been filetoupload echo "File (<a href=$upload_dir$filename>$filename</a>) uploaded!"; } else { //Print error echo "There was a problem moving your file"; exit(); } } ?> |