0% found this document useful (0 votes)
23 views4 pages

Code Upload Picture

Uploaded by

Hop Huynh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views4 pages

Code Upload Picture

Uploaded by

Hop Huynh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

action="<?php print $PHP_SELF?

>" enctype="multipart/form-data" method="post">


Last Name:<br /> <input type="text" name="name" value="" /><br />
Homework:<br /> <input type="file" name="homework" value="" /><br />
<p><input type="submit" name="submit" value="Submit Notes" /></p>
</form>

<?php
define ("FILEREPOSITORY","./");

if (isset($_FILES['homework'])) {

if (is_uploaded_file($_FILES['homework']['tmp_name'])) {

if ($_FILES['homework']['type'] != "application/pdf") {
echo "<p>Homework must be uploaded in PDF format.</p>";
} else {
$today = date("m-d-Y");
if (! is_dir(FILEREPOSITORY.$today)) {
mkdir(FILEREPOSITORY.$today);
}
$name = $_POST['name'];
$result = move_uploaded_file($_FILES['homework']['tmp_name'], FILEREPOSITORY.
$today."/"."$name.pdf");

if ($result == 1)
echo "<p>File successfully uploaded.</p>";
else
echo "<p>There was a problem uploading the homework.</p>";
}
}
}
?>











Code upload 2:

if ($_FILES["file"]["error"] > 0)
{
echo "Error: " . $_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 "Stored in: " . $_FILES["file"]["tmp_name"];
}




$target_path = "C:/wamp/www/Chuyendeweb/";
$target_path = $target_path . basename( $_FILES['file']['name']);
$_SESSION['target_path'] = $target_path;
$_SESSION['tempinfo'] = $_FILES['file']['tmp_name'];
if(move_uploaded_file($_SESSION['tempinfo'], $_SESSION['target_path'])) {
echo "The file has been uploaded!";
} else{
echo "There was an error uploading the file, please try again!";
}


if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 20000))
{
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("upload/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"upload/" . $_FILES["file"]["name"]);
echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
}
}
}
else
{
echo "Invalid file";
}





upload anh
$path = 'Baitap/';
$file = null;
for($i=0; $i<sizeof($_FILES["File"]["name"]); $i++)
{
if ($_FILES['File']['error'][$i] > 0)
{
echo "Error !";
}
else if(file_exists($path . $_FILES["File"]["name"][$i]))
{
echo "File exists !";
}
else
{
move_uploaded_file($_FILES['File']['tmp_name'][$i], $path .
$_FILES['File']['name'][$i]);
echo $_FILES['File']['name'][$i];
echo $_FILES['File']['type'][$i];
echo $_FILES['File']['size'][$i];
}

}

You might also like