הוסטס - פורום אחסון האתרים הגדול בישראל

הוסטס - פורום אחסון האתרים הגדול בישראל (https://hosts.co.il/forums/index.php)
-   פורום תיכנות (https://hosts.co.il/forums/forumdisplay.php?f=14)
-   -   בעיה עם קוד כלשהו בPHP (https://hosts.co.il/forums/showthread.php?t=19070)

LoLeR 04-04-06 23:34

בעיה עם קוד כלשהו בPHP
 
הכנתי קוד העלאה של קבצים לפי מדריך, ואחרי שאני מעלה את הקבצים דרך הטופס באינטרנט, אי אפשר להעביר אותם אליי, למחוק אותם, או לעשות שינוי כלשהו, ולא רואים אותם דרק הלוח בקרה.
אם אתם יכולים לתקן את הקוד, זה יהיה נפלא!
הנה:
PHP קוד:

<?PHP
//If the submit button is pressed:
if($_POST['submit'])
{
//Change this to the directory you would like to upload files to.
$directory "uploads/";
//Change this to the max file size you want users to be able to upload - File size is in bytes (1,024 Bytes = 1 Kilobyte (KB))
$max_file_size "20971520";
$allowedfile[] = "movie/avi"//.avi
$allowedfile[] = "image/gif"//.gif
$allowedfile[] = "movie/mpeg"//.mpeg
$allowedfile[] = "movie/mpg";  //.mpg
$allowedfile[] = "video/x-ms-wmv";  //.wmv
$allowedfile[] = "video/quicktime";  //.mov
//Check max file size
if (is_uploaded_file($_FILES["file"]["tmp_name"])) {
if(
$_FILES["file"]["size"]>$max_file_size) {
$is_uploaded "failed";
echo 
'Sorry, this file is too large. The maximum filesize is '.$max_file_size.' bytes, although your file is '.$_FILES["file"]["size"].'. ';
exit(); 
//If $is_upload = failed, then we stop the uploading process
}
//Check file type
if(!in_array($_FILES["file"]["type"],$allowedfile)) {
$is_uploaded "failed";
echo 
'Sorry, wrong file type, "'.$_FILES["file"]["type"].'" is not allowed. ';
exit(); 
//If $is_upload = failed, then we stop the uploading process
}

//Now, if $is_uploaded does NOT = failed, we remove invalid characters in the filename, and replace all spaces with underscores  
  
if($is_uploaded!="failed") {       
 
$replace = array("$","%","#","@","!","&","^","*","(",")","-");      
  
$new str_replace($replace,"",$_FILES["file"]["name"]);   
     
$fileName str_replace(" " "_" $new);
 
//If the directory defined in the beggining does not exist, we create it and CHMOD it to 777
if(! is_dir($directory)){
 
mkdir($directory,0777);
}
//Now we upload the file and check for errors
    
if (move_uploaded_file($_FILES["file"]["tmp_name"], $directory.$fileName)) {
echo 
"Your file, $fileName has successfully been uploaded!";                     }                         
else {
  echo 
'Sorry, your file has not uploaded.';
exit();
}
}
} else {
    echo 
'There has been an unknown error while uploading';
exit();
}
  }
?>
<!---Submit File Form--->
     <center>
        <form action="<?= $_SERVER['PHP_SELF'?>" method="post" enctype="multipart/form-data">
         <table>
<tr>
  <td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Choose File:</font></td>
<td><input type="file" name="file">
 <input name="submit2" type="submit" value="Upload File">
</td>
<input type="hidden" name="submit" value="true">
</tr>
</table>
</form>
</center>
<!---End Submit File Form--->

תודה :)

בניה 05-04-06 00:23

לש"ש


האם אתה רואה אותם בFTP?

LoLeR 05-04-06 11:36

כן, אני רואה בFTP, אבל אי אפשר לעשות איתם משהו..

Cool_DuDu 05-04-06 11:46

תשנה את התנאים אם הכפתור נשלח או לא..ל-
if(isset($_POST['submit']))

LoLeR 08-04-06 16:29

זה לא עזר :(
וגם איך אני מוחק את הקבצים האלה עכשיו?

חוטו 08-04-06 20:40

אם אתה לא מצליח למחוק דרך הFTP אז תעשה קובץ PHP חדש...
ובפנים תרשום:
PHP קוד:

<?
unlink
('שם הקובץ');
?>

ותשמור את הקובץ האותו תיקיה כמו התמונות...
או שאתה יכול לעשות:
PHP קוד:

<?
$file 
$_GET['file'];
unlink('$file');
?>

ותשמור את הקובץ בשם delete.php
ואז תכנס אליו ככה:
delete.php?file=מיקום הקובץ בשרת
ותשמור אותו בתיקיה הראשית של השרת(בדר"כ public_html)
ואז נגיד אם אתה רוצה למחוק את הקובץ שנמצא ב image/img.gif אתה מפעיל את הקובץ פעם אחת ככה:
delete.php?file=image/img.gif

מקווה שעזרתי:)

LoLeR 09-04-06 13:26

אממ..
אין אפשרות שאני אעשה הכל דרך השרת?

LosNir 09-04-06 18:48

ציטוט:

נכתב במקור על ידי Cool_DuDu
תשנה את התנאים אם הכפתור נשלח או לא..ל-
if(isset($_POST['submit']))

חחחח קרעת אותי.... מה זה קשור?
זה לא קשור בכלל!

לפותח האשכול, אין מה לעשות בנידון, ככה זה העלאת קבצים, כשמעלים קבצים אז השרת עושה CHMOD לקבצים ככה שלא יהיה אפשר להעביר אותם למחשב, ככה שכל הפעולות האחרות לא זמינות, כגון עריכה שינוי שם וכו' בגלל שכל הפעולות האלה מעבירות את הקובץ ללקוח ואז מעלות לשרת אחרי השינוי.
בקשר למחיקה, זה אפשרי אך אני לא יודע למה אצלך זה לא עובד.


כל הזמנים הם GMT +2. הזמן כעת הוא 09:05.

מופעל באמצעות VBulletin גרסה 3.8.6
כל הזכויות שמורות ©
כל הזכויות שמורות לסולל יבוא ורשתות (1997) בע"מ