Created
July 31, 2013 12:15
-
-
Save samundrak/6121472 to your computer and use it in GitHub Desktop.
trouble in multiple file upload
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class AppUpload{ | |
public $appName,$desc,$keyword,$price; | |
public $formName; | |
public function __construct(){ | |
if(isset($_POST['submit'])){ | |
$this->appName = $_POST['appName']; | |
$this->desc = $_POST['description']; | |
$this->keyword = $_POST['keyword']; | |
$this->price = $_POST['price']; | |
$this->formName = array(); | |
$this->formName[0] = 'file2'; | |
$this->formName[1] = 'file'; | |
$this->formName[2] = 'snapshot1'; | |
$this->formName[3] = 'snapshot2'; | |
$this->formName[4] = 'snapshot3'; | |
for($x = 0; $x <= 4; $x++){ | |
$this->renameMoveFile($this->formName[$x]); | |
} | |
} | |
} | |
private function renameMoveFile($filename){ | |
$fileType = $_FILES[$filename]['type']; | |
if($fileType == 'image/png' || $fileType == 'image/jpeg'|| $fileType == 'image/gif' || $fileType == 'image/jpg'){ | |
$fileCode = 0; | |
}else{ | |
$fileCode = 1; | |
} | |
$ext = $fileCode == 0 ? '.jpg' : '.zip' ; | |
$dir = $fileCode == 0 ? 'images' : 'downloads' ; | |
$path = '../app/'.$dir.'/'.$_FILES[$filename]['name']; | |
move_uploaded_file($_FILES[$filename]["tmp_name"],$path); | |
$newName = '../app/'.$dir.'/'.time().$ext; | |
rename($path,$newName); | |
return $newName; | |
} | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php $appupload = new AppUpload(); ?> | |
<form action="" method="post" enctype="multipart/form-data"> | |
<table width="600" border="1" cellspacing="0" cellpadding="0"> | |
<tr> | |
<td>App name</td> | |
<td><input name="appName" type="text" /></td> | |
</tr> | |
<tr> | |
<td>App thumbnail</td> | |
<td><input name="file" type="file" /></td> | |
</tr> | |
<tr> | |
<td>App Snapshot1</td> | |
<td><input name="snapshot1" type="file" /></td> | |
</tr> | |
<tr> | |
<td>App Snapshot2</td> | |
<td><input name="snapshot2" type="file" /></td> | |
</tr> | |
<tr> | |
<td>App Snapshot3</td> | |
<td><input name="snapshot3" type="file" /></td> | |
</tr> | |
<tr> | |
<td>App File</td> | |
<td><input name="file2" type="file" /></td> | |
</tr> | |
<tr> | |
<td>App Description</td> | |
<td><textarea name="description" cols="2" rows="2"style="margin: 2px; width: 366px; height: 107px;"> </textarea></td> | |
</tr> | |
<tr> | |
<td>App Keyword</td> | |
<td><textarea name="keyword" cols="2" rows="2" style="margin: 2px; width: 366px; height: 107px;"> </textarea></td> | |
</tr> | |
<tr> | |
<td>App Price</td> | |
<td><input name="price" type="number" /></td> | |
</tr> | |
<tr> | |
<td></td> | |
<td><input name="submit" type="submit" /></td> | |
</tr> | |
</table> | |
</form> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment