Click here to Skip to main content
15,886,519 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a scipt to upload zip file but i need to add I need to add _ (underscore) to file zip file name am uploading , but it is giving error , how do i resolve this?

What I have tried:

<form action="upload.php" enctype="multipart/form-data" method="post">
<input type="file" name="zipFile" accept="zip/*">
<input type="submit" name="Submit" value="Submit">
</form> 


$rand = rand(10,100);
$streplaceFileName = cleanSpecialCharacters($_FILES[‘zipFile’][‘name’]);
$zipFile = $rand."-".$streplaceFileName;$ds = DIRECTORY_SEPARATOR;
$storeFolder = ‘uploads/zip’;

if((!empty($_FILES)) && !empty($_FILES[‘zipFile’][‘name’])) {
if(preg_match(‘/[.](zip)$/’, $_FILES[‘zipFile’][‘name’])) {

$filename = $rand . "-" . $streplaceFileName;
$tempFile = $_FILES[‘zipFile’][‘tmp_name’];
$targetPath = $storeFolder . $ds;
$targetFile = $targetPath.$filename;
$check = move_uploaded_file($tempFile,$targetFile);
if($check) echo "ZipFile Uploaded Successfully!";
}
}

function cleanSpecialCharacters($string) {
$string = str_replace(‘ ‘, ‘-‘, $string); // Replaces all spaces with hyphens.
return preg_replace(‘/[^A-Za-z0-9.\-]/’, ", $string); // Removes special chars.
}
Posted
Comments
Richard MacCutchan 31-Jan-21 12:31pm    
What error, and where does it occur.
Member 11755075 31-Jan-21 12:48pm    
Warning: move_uploaded_file(uploads\nsnsbl0122"resp.zip) [function.move-uploaded-file]: failed to open stream: Invalid argument in C:\Program Files (x86)\EasyPHP-5.3.5.0\www\OE21\Chat\uploadzip.php on line 15
Richard MacCutchan 31-Jan-21 14:49pm    
Well you need to look at line 15 to see what it is trying to do. But more importantly you need to look at the actual value of any parameters at that point when the error occurs.
Member 11755075 31-Jan-21 23:59pm    
thank you :)
Member 11755075 31-Jan-21 12:55pm    
It works now , but sometimes it gave error , am confused why

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900