ذخیره ی فایل بارگذاری شده
سلام
میخوام یه فایلی رو که لود میکنم ذخیره کنه
خودم این کد رو نوشتم اما ارور میده
لطفا راهنمایی کنین
<?php
if($_FILES["upload"]["type"]=="image/gif")
{
if($_FILES["upload"]["error"]>0)
{
echo "مشکلی ایجاد شد.".$_FILES["upload"]["error"]."<br>";
}
else
{
echo "نام فایل:".$_FILES["upload"]["name"]."<br>";
echo "نوع فایل:".$_FILES["upload"]["type"]."<br>";
echo "اندازه فایل:".($_FILES["upload"]["size"]/1024)."<br>";
echo "محل فایل:".$_FILES["upload"]["tmp_name"]."<br>";
}
move_uploaded_file($_FILES["upload"]["tmp_name"],
"upload/".$_FILES["upload"]["name"]);
echo "upload/".$_FILES["upload"]["name"];
}
?>
نقل قول: ذخیره ی فایل بارگذاری شده
سلام دوست عزیز
فکر نکم کد شما مشکلی داشته باشه
احتمال داره توی کد html مشکلی وجود داشته باشه
کد زیر توی یه فایل به اسم test1.php بذار دقیقا کار میکنه و فایل آپلودی کنار خودش ذخیره می کنه
فقط به چند چیز توجه کن
محدودیت نوع فایل
$_FILES["upload"]["type"]=="image/gif"
تعریف فورم:
کد HTML:
<form enctype='multipart/form-data' action='test1.php' method='POST'>
مسیر ذخیره سازی:
$target = "".$_FILES["upload"]["name"];
<?php
if($_FILES["upload"]["type"]=="image/gif")
{
if($_FILES["upload"]["error"]>0)
{
echo "مشکلي ايجاد شد.".$_FILES["upload"]["error"]."";
}
echo var_dump($_FILES["upload"]);
$target = "".$_FILES["upload"]["name"];
move_uploaded_file($_FILES["upload"]["tmp_name"], $target);
echo "".$_FILES["upload"]["name"]."<br />";
}
?>
<form enctype='multipart/form-data' action='test1.php' method='POST'>
<input name="upload" type="file" />
<input type="submit" />
</form>
نقل قول: ذخیره ی فایل بارگذاری شده
سلام
نشدش کسی نیست راهنمایی کنه؟؟؟؟
نقل قول: ذخیره ی فایل بارگذاری شده
منظورتون از اینکه میگین نشد چیه؟ خطایی تولید شده؟ فایل ذخیره نمیشه؟ لطفاً مشکل رو دقیق بگین چیه تا بشه کمک کنیم. دکتر هم که میریم، وقتی میگیم آقای دکتر به دادم برس دارم میمیرم، مریضم! میگه: علائم مریضیتو بگو، همه یه روزی میمیریم!
نقل قول: ذخیره ی فایل بارگذاری شده
ارورش اینه:
( ! ) Notice: Undefined index: upload in C:\wamp\www\5\1.php on line 19
Call Stack
# Time Memory Function Location
1 0.0012 689256 {main}( ) ..\1.php:0
ولی خط 19برنامم مشکلی نداره این خط 19 برنامم:
if($_FILES["upload"]["type"]=="image/gif")
نقل قول: ذخیره ی فایل بارگذاری شده
خوب این خطا برای اینه که همون ابتدا با isset اصلاً چک نکردین ببینید ['FILES['upload_$ اصلاً وجود داره یا نه چون وقتی هنوز فرم ارسال نشده، فایلی وجود نداره که error و type و... رو بخوایم بررسی کنیم.
نقل قول: ذخیره ی فایل بارگذاری شده
این خطا نیست Notice هست و بار اولی که کد صفحه اجرا می شه و هنوز فایلی اسال نداره و متغییر $_FILE مقدار دهی نشده این خطا رو می ده
به هر حال برای رفع اون
کل کد php بالا رو داخل شرط IF بذارید:
if(isset($_FILES["upload"]))
{
if($_FILES["upload"]["type"]=="image/gif")
{
if($_FILES["upload"]["error"]>0)
{
echo "مشکلي ايجاد شد.".$_FILES["upload"]["error"]."";
}
echo var_dump($_FILES["upload"]);
$target = "".$_FILES["upload"]["name"];
move_uploaded_file($_FILES["upload"]["tmp_name"], $target);
echo "".$_FILES["upload"]["name"]."<br />";
}
}
نقل قول: ذخیره ی فایل بارگذاری شده
الانNoticeنمیده ولی هیچ چیزی هم نشون نمیده
منظورم اطلاعات تصویر و خود تصویر رو هست
نقل قول: ذخیره ی فایل بارگذاری شده
دوست گرامی، باور کنید اینطوری که شما دارین کار میکنید و اصول و... رو نخوندین و مستقیماً دارین کد مینویسید، به هیچ جا نمیرسین. اول مستندات و آموزشها رو مطالعه کنید و بعد کار کنید. اینطوری خودتون بیشتر از بقیه اذیت میشین. برنامه نویسی که مثل کار با فتوشاپ و... نیست که بدون مطالعه و تحقیق و با روش سعی و خطا بتونید توش موفق بشین.
نقل قول: ذخیره ی فایل بارگذاری شده
آخه این خودآزمایی کتاب هستش و باید برای معلممون ارسال کنم تا ظهر
خوهشا..........
نقل قول: ذخیره ی فایل بارگذاری شده
دوست عزیز خوب من دارم کد به صورت ساده شده برات می نویسم باقیه مخلفاتش دیگه با خودته
اطلاعات تصویر با این کد چاپ می کنه
echo var_dump($_FILES["upload"]);
طبق چیزی هم که خودت تو شرط زیر نوشته بودی باید فقط فایل تصویری با پسوند gif بهش بدی
if($_FILES["upload"]["type"]=="image/gif")
در ضمن کد فایل آپلود می کنه کنار خود فایل php تو صفحه نشونش نمی ده
در این حال کد زیر یه امتحان کن ببین دیگه خودشه :
<?php
if(isset($_FILES["upload"]))
{
if($_FILES["upload"]["type"]=="image/gif")
{
if($_FILES["upload"]["error"]>0)
{
echo "مشکلي ايجاد شد.".$_FILES["upload"]["error"]."";
}
echo var_dump($_FILES["upload"]);
$target = "".$_FILES["upload"]["name"];
move_uploaded_file($_FILES["upload"]["tmp_name"], $target);
echo "".$_FILES["upload"]["name"]."<br />";
echo "<img src='$target' alt='pic'/>";
}
else
{
echo "پسوند فایل انتخاب شده gif نیست";
}
}
?>
<form enctype='multipart/form-data' action='test1.php' method='POST'>
<input name="upload" type="file" />
<input type="submit" />
</form>