الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

[ تمت الإجابة ]رفع ملفات TXT فقط

بدأه so0oma في 18 مايو 2012 · 3 رد · 1,064 مشاهدة · في منتدى تطوير المواقع بـ PHP
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم ..

اريد رفع ملفات الى الموقع بس يكون نوع الملف TXT فقط

هذا الكود اللي استخدمته

<?php 
 $target = "upload/"; 
 $target = $target . basename( $_FILES['upload']['name']) ; 
 $ok=1;
$uploaded_type ='A.TXT';
$ext = $target['extension'];

if($ext !== 'txt' && $uploaded_type =="text/php"){
  //don't upload
  echo "No PHP files<br>"; 
 $ok=0; 
 } 



 //Here we check that $ok was not set to 0 by an error 
 if ($ok==0) 
 { 
 Echo "Sorry your file was not uploaded"; 
 } 

 //If everything is ok we try to upload it 
 else 
 { 
 if(move_uploaded_file($_FILES['upload']['tmp_name'], $target)) 
 { 
 echo "The file ". basename( $_FILES['upload']['name']). " has been uploaded"; 
 } 
 else 
 { 
 echo "Sorry, there was a problem uploading your file."; 
 } 
 } 
 ?>

المشكلة انه يرفع لي اي صيغة jpg,dox,.php.......

واللي ابغاه انه يرفع txtفقط

وكمان اقدر احدد اسم الملف ...

لانه الملف اللي راح ارفعه راح يستخدم في الموقع ولازم يكون اسم الملف نفس الملف اللي راح اشتغل عليه

ممكن احد يساعدني ؟؟؟

#2

تفضل اخي

<form enctype="multipart/form-data" action="upload.php?do=upload" method="POST">
Choose a file to upload: <input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload File" />
</form>



<?php 
if($do == "upload"){
$target_path = "uploads/";
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 
$ext01 = basename( $_FILES['uploadedfile']['name']);
$ext02  = $ext01;
$extension = explode(".", $ext02);
$ext = $extension[1]; 

if($ext !== 'txt' ){
echo "No TEXT files"; 
exit;
}

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    echo "The file ".  basename( $_FILES['uploadedfile']['name']). 
    " has been uploaded";
} else{
    echo "There was an error uploading the file, please try again!";
}
 }

 ?>
#3

ظهر لي خطأين

الاول انه $do

غير معرفه

والثاني

Notice: Undefined index: uploadedfile in C:\Program Files (x86)\EasyPHP-5.3.9\www\attend\upload.php on line 12

الuploadedfile مو اسم المجلد اللي احفظ فيه ؟؟

#4
so0oma كتب:

ظهر لي خطأين

الاول انه $do

غير معرفه

والثاني

Notice: Undefined index: uploadedfile in C:\Program Files (x86)\EasyPHP-5.3.9\www\attend\upload.php on line 12

الuploadedfile مو اسم المجلد اللي احفظ فيه ؟؟

HTML CODE

<form enctype="multipart/form-data" action="upload.php?do=upload" method="POST">
Choose a file to upload: <input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload File" />
</form>

PHP CODE

$target_path = "uploads/";
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 
$ext01 = basename( $_FILES['uploadedfile']['name']);
$ext02  = $ext01;
$extension = explode(".", $ext02);
$ext = $extension[1]; 

if($ext !== 'txt' ){
echo "No TEXT files"; 
exit;
}

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    echo "The file ".  basename( $_FILES['uploadedfile']['name']). 
    " has been uploaded";
} else{
    echo "There was an error uploading the file, please try again!";
}

اسم مجلد الحفظ

$target_path = "uploads/";

تم تعديل هذه المشاركة بواسطة Saleh.Al-Thiyab في 19 مايو 2012 في 09:16

مواضيع مشابهة

عدد الزوار حالياً

المتواجدون خلال آخر دقيقتين · يتحدّث كل ٣٠ ثانية

—الإجمالي—أعضاء مسجّلون—زوار بدون تسجيل

جارٍ التحقق من المتواجدين…