The move_uploaded_file()
needs 2 arguments.
The temporary file destination (which is closed in PHP.ini as a temporary uploading directory) and the final destination, indicated by you.
Note that this board already has to exist. If it does not exist yet (and with the right permissions) you must create it. You can create the board as @Diego suggested.
$temp = $_FILES["new_image"]["tmp_name"];
$error = $_FILES["new_image"]["error"];
if ($error > 0) die("Algo correu mal!... code $error.");
move_uploaded_file($temp, $finalPath); // $finalPath defenida por tí
Keep in mind that it is not safe to upload uploaded files into public_html
. At least check if the file is an image like this:
$temp = $_FILES["new_image"]["tmp_name"];
$error = $_FILES["new_image"]["error"];
$name = $_FILES["new_image"]["name"];
$uploadPath = "/home/storage/b/71/d0/site1390582818/upload/".$name;
$finalPath = "/home/storage/b/71/d0/site1390582818/public_html/upload/".$name;
if ($error > 0) die("Algo correu mal!... code $error.");
move_uploaded_file($temp, $uploadPath);
$size = getimagesize($uploadPath);
if(!$size) die('Algo correu mal!...');
rename($uploadPath, $finalPath);
The upload worked, but in the "photo" field of the table...
– Valloto
@Valloto as well in the "photo" field of the table? you can explain better?
– Sergio
I am saving the path and the name of the image in the picture table.. in the photo column! Getting as follows ' path/image.png '
– Valloto
@Valloto "table" and "column" is used in databases like Mysql, is that what you’re talking about? or do you mean folder/file? in the case of folder/file you can change the path you want in the variables
$finalPath
and$uploadPath
and the code will do what you want.– Sergio
I was able to make the recording and also visualize the images, the code ended up being very simple, I will finish the service and put the code for you to help me with patterns. Thank you
– Valloto