-
آپلود عکس
با سلام
من می خوام موقعی که عکسی آپلود می شه اسمش رو عوض کنم و چون اسمش توی بانک ذخیره می شه هم نام id ردیف خودش بشه و ضمنا بعدا بتونم با پاک کردن ردیفش از توی بانک این فایل عکس رو هم پاک کنم
کسی می دونه چطوری می تونم این دو تا کارو انجام بدم
فقط تغییر نام و پاک کردن عکس رو بگید بقیش کاری نداره- متشکر
-
اول از همه یه فایل آtml درست کن کدش هم اینه:
[HTML]<form enctype="multipart/form-data" action="upload.php" method="POST">
Please choose a file: <input name="uploaded" type="file" /><br />
<input type="submit" value="Upload" />
</form> [/HTML]
بعد فایل upload.php رو درست کن:
[PHP]
<?php
//This function separates the extension from the rest of the file name and returns it
function findexts ($filename)
{
$filename = strtolower($filename) ;
$exts = split("[/\\.]", $filename) ;
$n = count($exts)-1;
$exts = $exts[$n];
return $exts;
}
//This applies the function to our file
$ext = findexts ($_FILES['uploaded']['name']) ;
[/PHP]
تا اینجا پسوند فایل رو پیدا کردیم حالا فایل رو به صورت رندم تغییر نام میدیم تغییرات رو باید اینجا بدی:
[PHP]
//This line assigns a random number to a variable. You could also use a timestamp here if you prefer.
$ran = rand () ;
//This takes the random number (or timestamp) you generated and adds a . on the end, so it is ready of the file extension to be appended.
$ran2 = $ran.".";
//This assigns the subdirectory you want to save into... make sure it exists!
$target = "images/"; //This combines the directory, the random file name, and the extension
$target = $target . $ran2.$ext;
[/PHP]
این قسمت هم برای ذخیره ی فایل rename شده:
[PHP]
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
{
echo "The file has been uploaded as ".$ran2.$ext;
}
else
{
echo "Sorry, there was a problem uploading your file.";
}
?>
[/PHP]
خودت روش تغییرات ایجاد کن برای حذف فانکشن unlink() استفاده کن دیگه حوصله توضیح ندارم!!:46:
-
از توضیحاتت ممنونم
اگه وقت کردی یه توضیحی هم راجع به فانکشن unlink() بدی ممنون می شم
-
با اجازه دستور unlink فایل مورد نظر شما رو پاک میکنه
-
خب وقتی میخای عکس رو پاک کنی از توی مای اس کیو ال اسمشو پاک کن بعد هم با unlink() عکسو پاک کن