Question:
the PHP file uploadFile.php (what is the best way to write the code.)?
anonymous
2009-12-07 22:17:52 UTC
I need the best way to write the file uploadFile.php in the dummies book I have two problems for uploading. I have writen the codes, and can't transfer the image after I've uploaded. The file selection, and picture text show, but they don't show the image uploded. Please show me a good PHP problem for uploading files. I haven't used MySql.
Six answers:
Robin T
2009-12-07 22:50:20 UTC
Show us your code and we'll try to find what's wrong with it.
josh.rofl
2009-12-07 22:56:16 UTC
There are two parts.



1. HTML form. For uploading a file, you must put indicate enctype="multipart/form-data" in the
tag.



2. PHP upload. You're going to need a folder on your website server that is chmoded to 777. This gives your php script permission to create/save a new file in this folder. For example, create a folder called /upload/ in the same directory as your upload.php. Now use this code:



http://www.webcheatsheet.com/php/file_upload.php
anonymous
2016-10-19 11:13:34 UTC
That internet site could look to do a redirect on your internet site, so which you will ought to write the internet site on the URL that is redirecting to. so some distance as writing HTML on a Hypertext Preprocessor internet site, there are 2 procedures: your HTML code right here Or the two one will artwork, and the two one will produce the same HTML code.
?
2009-12-07 22:31:15 UTC
This script will allow you to upload files from your browser to your hosting, using PHP. The first thing we need to do is create an HTML form that allows people to choose the file they want to upload.





Please choose a file:








This form sends data to the file "upload.php", which is what we will be creating next to actually upload the file.
anonymous
2009-12-08 12:48:24 UTC

/********************************

files.class.php

********************************/

class files{

var $Error;

var $goback;



function files(){

}



function file_form($UserInput){

echo "
**Information**
Max upload file size is 10MB

File to upload:
Access:
File Comments:
";

}



function add_file($UserInput){

require_once('static.class.php');

if(file_exists("upload/" . $_FILES['file_to_upload']['name']))

{

$this->file_form($UserInput);

echo "
The file already exists! Delete first!
Try again or $this->goback!
";

$this->Error == true;

exit;



}

else

{

//Add the file

$this->move_temp_file = move_uploaded_file($_FILES['file_to_upload']['tmp_name'], "upload/" . $_FILES['file_to_upload']['name']);

if(!$this->move_temp_file)

{

$this->file_form($UserInput);

echo "
There was a problem uploading your file!
Try again or $this->goback!
Contact support!
";

$this->Error == true;

exit;

}

else

{

//Add file information to database

//Generate File ID

$this->file_ID = md5($_SESSION['Path'] . "/" . $_FILES['file_to_upload']['name'] . date($_SESSION['UNIX_EP']));

$this->file_path = $_SESSION['Path'] . "/" . $_FILES['file_to_upload']['name'];

$Nfile_name = $_FILES['file_to_upload']['name'];

$Nfile_type = $_FILES['file_to_upload']['type'];

$Nfile_size = $_FILES['file_to_upload']['size'];



$IVal = $_FILES['file_to_upload']['size'];

$file_size = new static_class();

$file_size->StaticFSize($IVal);

$this->read_file_size = $file_size->FDS;



$this->query_string = "INSERT INTO files (id, UID, File_Name, File_ID, File_Type, File_Path, File_Access, File_DTG, File_Size, Read_File_Size, File_Count, Comments) VALUES('0','$_SESSION[UID]', '$Nfile_name','$this->file_ID','$Nfile_type','$this->file_path','$UserInput[Access]','" . date($_SESSION['DTG']) . "','$Nfile_size','$this->read_file_size','0','" . addslashes($UserInput['FileComments']) . "')";

$this->query = mysql_query($this->query_string);

if(!$this->query)

{

$this->delete_file = unlink("upload/" . $_FILES['file_to_upload']['name']);

$this->file_form($UserInput);

$space_left_message = ($this->space_left <= "0") ? "You do not have any space left" : "Space left:" . $file_size->FDS;

echo "
Error adding file to database! No file uploaded! $this->goback
";

$this->Error == true;

exit;

}

else

{

$this->file_form($UserInput);

echo "
File upload complete!
";

$this->Error == false;

}



}

}

}







function validate_file($UserInput){

require_once('static.class.php');

$this->goback = "(Go Back)";

$this->max_upload_size=pow(1024,2)*10;



//Calculate the file size

$file_size = new static_class();

$IVal = $_FILES['file_to_upload']['size'];

$file_size->StaticFSize($IVal);

$UserInput['file_size'] = $file_size->FDS;



//Check to see if user has enough space left

$this->max_disk_space = pow(1024,2)*10;

//Add all file s
Wallace
2009-12-09 00:19:33 UTC
You can visit this website: http://www.webcheatsheet.com


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...