It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I have written these scripts to delete files (image, in fact) in a directory but have the choice to decide which one to delete and view before hand. The view.php script seems to be working fine, however the delete.php doesn't seem to be functioning because the images are not removing.
here are the scripts:
view.php
<?php
$path = '../product-uploads/gloves/'; // path for each page
$files = glob("{$path}*.*"); // Get the files
$files = array_filter($files, 'is_file'); // Get rid of directories
$dates = array_map('filectime', $files); // Get the creation times.
$md5s = array();
array_multisort($dates, $files, SORT_NUMERIC); // in order of creation
foreach ($files AS $file)
{
$hash = md5_file($file);
if (!in_array($hash, $md5s))
{
$md5s[] = $hash;
echo "<img src=\"$file\" /> <br />
<form action=\"delete.php\" method=\"post\">
<input type=\"hidden\" name=\"Name\" value=\"$file\">
<input type=\"submit\" value=\"Delete\">
</form>";
}
}
?>
delete.php
<?php
$path = '../product-uploads/gloves/';// images are here
$Name = $_POST['Name'];
$PathFile = $path.$Name;
$PathFile = basename($PathFile);
header('Location: view.php');
?>
This is because you don't remove the images in your delete.php
Use unlink on pathfile.
Related
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
i am trying to upload image through following code.
although my if condition is executing as shown below but image is not moving to the specified path given by me. my code is below.
here is my html code
<form enctype="multipart/form-data" action="catcher.php" method="POST">
Send this file: <input name="userfile" type="file" />
<input type="submit" value="Send File" />
</form>
and here is my php code
<?php
$uploaddir = '/xampp/project/';
echo '<pre>';
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploaddir)) {
echo "File is valid, and was successfully uploaded.\n";
} else {
echo "Possible file upload attack!\n";
}
echo 'Here is some more debugging info:';
print_r($_FILES);
print "</pre>";
?>
can any body point out whats wrong with my code i mean why the image i am trying to upload is not moving to the specified path,,
move_uploaded_file() requires the second parameter to be destination file, not directory.
You could do:
$filename = $uploaddir . basename($_FILES['userfile']['tmp_name']);
if( move_uploaded_file($_FILES['userfile']['tmp_name'], $filename)){
// ...
But there is good chance that multiple users will try to upload files with the same name, so I strictly recommend to handle this possibility.
$folder = "../images/stories/";
$result = move_uploaded_file($_FILES['excel']['tmp_name'], $folder.$filename);
Give destination folder name. (In above code, $folder is destination path variable)
You can see detail on this function:
function upload($name,$tmp_name){
$fileextarr=explode('.',$name);
$fileextarr[0];
$fileext=$fileextarr[count($fileextarr)-1];
$fpath = "../images/stories/lab_excel/";
$filename = ereg_replace(" ","_",$fileextarr[0]).'.'.$fileext;
//You can use restriction on file extensions also. (not necessary)
if($fileext=="xls" || $fileext=="xlsx" || $fileext=="doc"|| $fileext=="docx" || $fileext=="jpeg" || $fileext=="png" || $fileext=="gif" || $fileext=="tiff" || $fileext=="bmp" || $fileext=="jpg")
{
$uploadedfile = $filename;
}
//Here is the use of destination path:
$folder = "../images/stories/lab_excel/";
$result = move_uploaded_file($_FILES['excel']['tmp_name'], $folder.$filename);
/*echo $folder.$_FILES['excel']['name'];
die();*/
if($result){
$msg="File Uploaded Successfully";
return $folder.$filename;
}
else
{
return false;
}
}
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I am currently making a website where you can upload and download files like a cloud server or something of that sort. I was just wondering what happens if i dont have space on a Hard drive how would i tell PHP to upload to upload to a different hard drive and just stuff like that?
i have this code and i will be adding security but right now im testing:
<?php
set_time_limit(30000);
session_start();
include('../Connect/Connect.php');
$User = $_SESSION['User'];
$Get = 'SELECT * FROM Users WHERE Username = "'.$User.'"';
$Files = $_FILES['File'];
if(isset($User))
{
if(!empty($Files))
{
if($Result = $Connect->query($Get))
{
while($Row = $Result->fetch_assoc())
{
$Limit = $Row['Limit'];
for($X = 0; $X < count($Files['name']); $X++)
{
$Name = $Files['name'][$X];
$TMP = $Files['tmp_name'][$X];
move_uploaded_file($TMP, '../Users/' . $User . '/' . $Name);
}
}
}
}
}
else
{
header("location:../");
}
header("location:index.php");
$Connect->close();
?>
You could always use disk_free_space() before you try to upload/move files. Also, move_uploaded_file will probably return false, but that can be also because of other issues such as permissions.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I have this PHP script from a file uploader. It is generating a XML file, but every-time I upload a new item it replaces the current nodes instead of adding to the "tree".
<?php
$todayDate = $_POST['todayDate'];
$Name = $_POST['Name'];
$Email = $_POST['Email'];
$filename = $_FILES['Filedata']['name'];
$filetmpname = $_FILES['Filedata']['tmp_name'];
$fileType = $_FILES["Filedata"]["type"];
$fileSizeMB = ($_FILES["Filedata"]["size"] / 1024 / 1000);
move_uploaded_file($_FILES['Filedata']['tmp_name'], "images/".$filename);
$xml = new XMLWriter;
$xml->openMemory();
$xml->startDocument( '1.0' , 'iso-8859-1' );
$xml->startElement("galeria");
$xml->writeElement("Name", $Name);
$xml->writeElement("Email", $Email);
$xml->endElement();
$file = fopen('data.xml','w+');
fwrite($file, $xml->outputMemory(true));
fclose($file);
try $file = fopen('data.xml', 'a'); I think that is the correct way to append a file
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
i found this code:
<?php
$path_to_file = 'c:\wamp\www\FindReplace\File.txt';
$file_contents = file_get_contents($path_to_file);
$file_contents = str_replace("Paul",",HHH",$file_contents);
file_put_contents($path_to_file,$file_contents);
?>
It's working very well if it's only one file but how to do if i want to Find and Replace in all *.txt file of my folder?
THank you
What about this?
It should take care of running your replace on all .txt-files, regardless of how many sub-folders you got in your path folder.
$path = realpath(__DIR__ . '/textfiles/'); // Path to your textfiles
$fileList = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path), \RecursiveIteratorIterator::SELF_FIRST);
foreach ($fileList as $item) {
if ($item->isFile() && stripos($item->getPathName(), 'txt') !== false) {
$file_contents = file_get_contents($item->getPathName());
$file_contents = str_replace("Paul",",HHH",$file_contents);
file_put_contents($item->getPathName(),$file_contents);
}
}
find /path/to/your/project -name '*.txt' -exec php yourScript.php {} \;
Then modify your script to use command line argument $argv[1] as the file path.
You can use useful glob(), internal PHP function
$files_in_your_folder = glob('c:\wamp\www\FindReplace\*');
So for your specific case:
<?php
foreach(glob('c:\wamp\www\FindReplace\*') as $path_to_file) {
$file_contents = file_get_contents($path_to_file);
$file_contents = str_replace("Paul",",HHH",$file_contents);
file_put_contents($path_to_file,$file_contents);
}
?>
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
Hi i am looking for script witch lists directory's from ftp and read's all files from the listed folder..Is there something that can help me?
> //open the dir
$sub = ($_GET['dir']);
$path = 'store/'.$diro.'/';
$path = $path . "$sub";
$dh = opendir($path);
$i=1;
while (($file = readdir($dh)) !== false) {
if($file != "." && $file != "..") {
if (substr($file, -4, -3) =="."){
echo "$i. $file ";
}else{
echo "$i. $file";
}
$i++;
}
}
closedir($dh);
I did a quick Google, and there a MILLIONS of responses to this question.
The fourth result is a complete code sample.
http://www.phpreg.com/index.php?option=com_content&task=view&id=158&Itemid=28
Something like....
<?php
$connect = ftp_connect("ftp.hostname.com");
$result = ftp_login($connect, "username", "password");
$a = ftp_nlist($connect, "code22");
foreach($a as $value){
echo $value, "<BR>";
}
?>