This information would of been nice 2 hours ago.
You need to specify the full absolute path to that folder.
This information would of been nice 2 hours ago.
You need to specify the full absolute path to that folder.
I did this…
sudo chmod -R 0777 /var/www/part/img
[Sun Mar 11 23:56:45.732334 2018] [:error] [pid 7769] [client ::1:36768] PHP Warning: move_uploaded_file(/img/user_upl/home_icon_android.png): failed to open stream: No such file or directory in /var/www/part/upload.php on line 39, referer: http://localhost/part/test.html
[Sun Mar 11 23:56:45.732380 2018] [:error] [pid 7769] [client ::1:36768] PHP Warning: move_uploaded_file(): Unable to move '/tmp/phpyyjJ4A' to '/img/user_upl/home_icon_android.png' in /var/www/part/upload.php on line 39, referer: http://localhost/part/test.html
Changing this line
//$target_dir = "/img/user_upl/";
to
$target_dir = "img/user_upl/";
Seems to resolve it.
There are so much problems with your script by the way.
undefined index
error if you try accessing the file directly.if(isset($_POST['submit']))
which should not be relied on.To fix these problems, I suggest
$_SERVER['REQUEST_METHOD']
submission checking.tmp
file is an image instead of the type of the file extension since $_FILES[...]['type']
actually refers back to the mime
type of the file extension. Though apparently you are already doing this. So you don’t need $_FILES[...]['type']
.IMG_xxxx.JPG
or IMG_xxxx.jpg
.$_SERVER['REQUEST_METHOD']
instead of the amateur hack.That was example I tried to learn from w3 school…
w3schools
is not a good place you want to be learning PHP
code from. I have already done an extensive discussion on uploading systems and how to implement proper security. You can find them if you dig deep enough on this forum.
Last question:)
How would I place some parts of the code into different file yet be able to share variables as if they were in the same file?
I’d say use require
. People abuse the include
function too much not understanding what it really does.
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.