When added with images, the name <name> <format> is assigned, and it must be <name>. <Format> Here is a piece of code responsible for this:

$dir='/bol/img/'; $format="jpeg"; $basename=basename($file); $up_file=$dir.'.'.$basename; echo ($up_file); if (is_uploaded_file($_FILES['myfile']['tmp_name'])) { $n=mt_rand(0,997); $file_path=$dir.$n.$format; if (!file_exists($file_path)) { 

And one more question: how to correctly specify the path in $ dir = '/ bol / img /'; Otherwise, he writes an error:

 localhost/bol/img/.5VJE21LC.jpglocalhost/bol/img/791jpeg Warning: move_uploaded_file(localhost/bol/img/791jpeg) [function.move-uploaded-file]: failed to open stream: No such file or directory in C:\xampplite\htdocs\bol\admin\img.php on line 45 Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\xampplite\tmp\php5AC3.tmp' to 'localhost/bol/img/791jpeg' in C:\xampplite\htdocs\bol\admin\img.php on line 45 

If at all the full path of this folder is C:\xampplite\htdocs\bol\img

  • Is this all your code or is it a little higher? Here you can not see how you translate from the tmp folder in / bol / img - Farhod
  • This is all related to working with files. Files are loaded all ok. Only problem with names. does not put a dot between the name and the file extension (((((( - new_russian_man

2 answers 2

In the code (in the question which) you need to fix the line

 $file_path=$dir.$n.$format; 

on

 $file_path=$dir.$n.".".$format; 

    About your code should look like this:

     $dir='/bol/img/'; if(isset($_FILES["myfile"])) { $myfile = $_FILES["myfile"]["tmp_name"]; $myfile_name = $dir.$_FILES["myfile"]["name"]; if(move_uploaded_file($_FILES['myfile']['tmp_name'], $myfile_name)) { echo "Upload ok"; } else { echo "error Move file"; } }