Symbianize Forum

Most of our features and services are available only to members, so we encourage you to login or register a new account. Registration is free, fast and simple. You only need to provide a valid email. Being a member you'll gain access to all member forums and features, post a message to ask question or provide answer, and share or find resources related to mobile phones, tablets, computers, game consoles, and multimedia.

All that and more, so what are you waiting for, click the register button and join us now! Ito ang website na ginawa ng pinoy para sa pinoy!

Pa-tulong naman po: About PHP

hardcorekid03

 
 
Symbianize Shaman
Advanced Member
Messages
1,422
Reaction score
751
Points
223
Space Stone
Reality Stone
Time Stone
Power Stone
Soul Stone
Mind Stone
Hi, newbie po ako sa php, tanong ko lang po sana kung pano kunin yung value ng textbox para gawing filename nung i-uupload kong image sa directory. ito po ang codes ko

<?php
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
// Check if image file is a actual image or fake image
if(isset($_POST["submit"])) {
$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
if($check !== false) {
echo "File is an image - " . $check["mime"] . ".";
$uploadOk = 1;
} else {
echo "File is not an image.";
$uploadOk = 0;
}
}
// Check if file already exists
if (file_exists($target_file)) {
echo "Sorry, file already exists.";
$uploadOk = 0;
}
// Check file size
if ($_FILES["fileToUpload"]["size"] > 500000) {
echo "Sorry, your file is too large.";
$uploadOk = 0;
}
// Allow certain file formats
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
&& $imageFileType != "gif" ) {
echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
$uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}
}


?>

salamat po sa tutulong :)
 
assuming na meron ka maayos na form na meron textbox - <input type="text" name="imageName">

upon form submission, dalawang data array ang maipapasa jan, yung $_FILES - nandito yung lahat ng data na may kinalaman sa file na ia-upload mo, tsaka $_POST - nandito naman ung ibang laman ng form mo, dito sasama ung textbox value.

Nakikita mo ito?

Code:
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file))

Yan ang function na maga-upload / mag-transfer ng file mo papunta sa server directory, ang syntax nyan ay

Code:
move_uploaded_file(<file to be uploaded>, <upload directory and new filename>)

ung 1st parameter ng function na yan ay manggagaling sa $_FILES array mo - $_FILES["fileToUpload"]["tmp_name"].
ung 2nd parameter ay manggagaling yan sa kung ano ang ii-specify mo,

Code:
$temp = explode(".", $_FILES["file"]["name"]); // kailangan ito para "ma-extract ung file extension ng file. ang magiging value ng $temp ay jpg, bmp, xls, xlsx r kung ano mang file extension
$target_file = $target_dir . $_POST['imageName'] . '.' . end($temp); // kinuha lang dito ung last part ng exploded array, kasi un ung may hawak sa extension name, tapos ikakabit natin sa filename na ipapalit natin sa original, ia-assign uli ito sa $target_file

#tapos dadaan sa standard checking kung yung new filename ay existing sa upload directory, para maiwasan ang file duplication
if (file_exists($target_file)) {
echo "Sorry, file already exists.";
$uploadOk = 0;
}

#proceed with your current code
 
assuming na meron ka maayos na form na meron textbox - <input type="text" name="imageName">

upon form submission, dalawang data array ang maipapasa jan, yung $_FILES - nandito yung lahat ng data na may kinalaman sa file na ia-upload mo, tsaka $_POST - nandito naman ung ibang laman ng form mo, dito sasama ung textbox value.

Nakikita mo ito?

Code:
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file))

Yan ang function na maga-upload / mag-transfer ng file mo papunta sa server directory, ang syntax nyan ay

Code:
move_uploaded_file(<file to be uploaded>, <upload directory and new filename>)

ung 1st parameter ng function na yan ay manggagaling sa $_FILES array mo - $_FILES["fileToUpload"]["tmp_name"].
ung 2nd parameter ay manggagaling yan sa kung ano ang ii-specify mo,

Code:
$temp = explode(".", $_FILES["file"]["name"]); // kailangan ito para "ma-extract ung file extension ng file. ang magiging value ng $temp ay jpg, bmp, xls, xlsx r kung ano mang file extension
$target_file = $target_dir . $_POST['imageName'] . '.' . end($temp); // kinuha lang dito ung last part ng exploded array, kasi un ung may hawak sa extension name, tapos ikakabit natin sa filename na ipapalit natin sa original, ia-assign uli ito sa $target_file

#tapos dadaan sa standard checking kung yung new filename ay existing sa upload directory, para maiwasan ang file duplication
if (file_exists($target_file)) {
echo "Sorry, file already exists.";
$uploadOk = 0;
}

#proceed with your current code

thanks sir, nagawa ko na po, maraming salamat :) ito yung naging code ko

$target_dir = "uploads/";
$file_parts = explode('.', $_FILES["fileToUpload"]["name"]);
$ext = $file_parts[count($file_parts) - 1];
$target_file = $target_dir . $_POST['tin']. '-'.$_POST['ftype']. '-'. $_POST['fmonth']. '.' . $ext;
$uploadOk = 1;$file_parts = explode('.', $_FILES["fileToUpload"]["name"]);
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
 
Back
Top Bottom