D
D
Dmitry2013-12-08 15:33:06
PHP
Dmitry, 2013-12-08 15:33:06

How to implement uploading files to server [php/apache]?

Worth OpenServer . The file upload form is written correctly. The file seems to be loading, I look at the dump, everything is in order there:

string(14) "H:\phpD394.tmp"
But the file, as such, is not there. What could be the problem? In the PHP config I edit the temporary directory - infa from the dump changes but the file is not observed. All this happens under Windows.

Answer the question

In order to leave comments, you need to log in

7 answer(s)
V
Victor, 2013-12-08
@another_dream

Do I misunderstand that "at the end of the script, if the received file has not been renamed or moved, it will be automatically deleted from the temporary folder"? That is, you should use the move_uploaded_file function as suggested.

E
Eugene, 2013-12-08
@Nc_Soft

There will be no print_r($_FILES);
conversation

D
Dmitry, 2013-12-08
@another_dream

<?php
define('GW_UPLOADPATH', 'images/');
$name=$_POST['name'];
$score=$_POST['score'];
$pic = $_FILES['screenshot'];
$pic=move_uploaded_file($_FILES['screenshot'], GW_UPLOADPATH);
?>

All right? The file is taken from the form, processed in PHP, moved from the temporary to the /images/ directory, right?
But dump "$pic" says:
bool(false)

D
Dmitry, 2013-12-08
@another_dream

string(14) "H:\phpEB58.tmp"
Is it supposed to save the file like this, or should the name match the file?

D
Dmitry, 2013-12-08
@another_dream

@Nc_Soft please:

Array ( [screenshot] => Array ( [name] => WIN_20131201_052047.JPG [type] => image/jpeg [tmp_name] => H:\phpB65.tmp [error] => 0 [size] => 122294 ) )

D
Dmitry, 2013-12-08
@another_dream

Hmm ... as I understand it, when trying to move, he swears:

Warning: move_uploaded_file(C:/srv/OpenServer/domains/localhost/images/) [function.move-uploaded-file]: failed to open stream: Permission denied in C:\srv\OpenServer\domains\localhost\tmp\addscore .php on line 29
Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'H:\phpABBE.tmp' to 'C:/srv/OpenServer/domains/localhost/images/' in C: \srv\OpenServer\domains\localhost\tmp\addscore.php on line 29

D
Dmitry, 2013-12-08
@another_dream

?php

$name=$_POST['name'];
$score=$_POST['score'];
$uploads_dir = '/images';
$tmp_name = $_FILES["screenshot"]["tmp_name"];
$name = $_FILES["screenshot"]["name"];
move_uploaded_file($tmp_name, "$uploads_dir/$name");

if ($_POST['submit']==true) {
  $mysqli->query("INSERT INTO guitar VALUES(0, NOW(), '$name', '$score', '$pic')"); 
} 
?>

The folder exists. Everything is perfect to perform. But still the same:
Warning: move_uploaded_file(/images/WIN_20131204_232139.JPG) [function.move-uploaded-file]: failed to open stream: No such file or directory in C:\srv\OpenServer\domains\localhost\tmp\addscore.php on line 35
Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'H:\php49F4.tmp' to '/images/WIN_20131204_232139.JPG' in C:\srv\OpenServer\domains\localhost\tmp\ addscore.php on line 35

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question