Bu ancak ben zor gerçekleştirmek için bulma yaşıyorum, muhtemelen basit bir soru.
Ben bir php sınıfı ile denir ("class.upload.php" kod * aşağıda) var:
<?php
$upload = new upload();
$upload->upload_file();
?>
bu yüzden bir test sayfasında öyle gibi olurdu:
<?php
$upload = new upload();
$upload->upload_file();
?>
<form action="" method="post" enctype="multipart/form-data">
<input type="file" id="real_upload" class="hide" name="file" />
<input type="submit" id="real_submit" class="hide" value="Upload" />
</form>
Sorun ben ne istiyorsun "galeri yükleme" segmentinde geçirdi kez bu sınıf dosya upload sahip olmaktır, web sitesi parçaları için bu yükleme sistemi kullanıyorum olduğunu:
<?php
$mysql_link = mysql_connect("localhost", "", "");
mysql_select_db("") or die("Could not select database");
while($counter <= count($photos_uploaded)) {
if($photos_uploaded['size'][$counter] > 0) {
if(!array_key_exists($photos_uploaded['type'][$counter], $known_photo_types)) {
$result_final .= "File ".($counter+1)." is not a photo<br />";
}
else {
mysql_query( "INSERT INTO gallery_photos(`photo_filename`, `photo_caption`, `photo_category`) VALUES('0', '".addslashes($photo_caption[$counter])."', '".addslashes($_POST['category'])."')" );
$new_id = mysql_insert_id();
$filetype = $photos_uploaded['type'][$counter];
$extention = $known_photo_types[$filetype];
$filename = $new_id.".".$extention;
mysql_query( "UPDATE gallery_photos SET photo_filename='".addslashes($filename)."' WHERE photo_id='".addslashes($new_id)."'" );
}
?>
Bu nasıl yaklaşım?
Teşekkürler, Keiran
class.upload.php
<?php
class Upload {
//File Max Size:
protected $max_file_size = 5;
public function upload_file() {
//Check for upload request:
if(isset($_FILES['file'])) {
//Set File Information:
$file = array(
'name' => $_FILES['file']['name'],
'type' => $_FILES['file']['type'],
'size' => $_FILES['file']['size'],
'temp' => $_FILES['file']['tmp_name'],
'error' => $_FILES['file']['error']
);
//Check if it is under the max size limit
if($file['size'] < ($this->max_file_size * 1048576)) {
//Filename:
$filename = strtolower($file['name']);
$filename = str_replace(" ","_",$filename);
//Check for a custom path location, if none exists it will load into a file associated directory
if (isset($_REQUEST['customPath'])) {
$path = 'uploads/'.$_REQUEST['customPath'].'/';
} else {
$path = 'uploads/'.$file['type'].'/';
if(!file_exists($path) && !is_dir($path)) {
mkdir($path, "511", true);
}
}
//Now lets more the file:
$move_file = move_uploaded_file($file['temp'], $path . $filename);
if($move_file) {
echo 'uploads/'.$filename;
}
} else {
echo 'Your file is too big to upload to our server.';
}
}
}
}
?>