Why do my uploaded files not exist in my filesystem and are not returned by my PHP commands? -
i'm having trouble creating form upload , store images.
after uploading (submitting form), print_r($files)
function:
array ( [image] => array ( [name] => 4hfoetn.jpg [type] => image/jpeg [tmp_name] => c:\windows\temp\php151f.tmp [error] => 0 [size] => 70107 ) )
however, when navigating c:\windows\temp\ in file browser, file not exist.
furthermore, when run:
$tmp_image_dir = basename($_files['image']['tmp_name']); echo "<img src=\"" . $tmp_image_dir . "\">" . "<br>";
no image shows up.
also, when run:
$image_dir = "/images/"; $image_dir = $image_dir . basename($_files['image']['name']); if(move_uploaded_file($_files['image']['tmp_name'], $image_dir)) echo "image uploaded successfully" . "<br>";
i not readout of "image uploaded successfully"
then, pretty obviously, when run:
echo "<img src=\"" . $image_dir . "\">" . "<br>
i image placeholder no image.
make sure $image_dir
exists, if not create mkdir
or manually.
dont need use basename
in $_files["image"]["name"]
since basename of file.
try below code
<?php $image_dir = "images/"; if ( !file_exists( $image_dir ) ) { mkdir( $image_dir, 0755 ); } $image_dir = $image_dir.$_files["image"]["name"]; if ( move_uploaded_file( $_files["image"]["tmp_name"], $image_dir ) ) { echo "image uploaded successfully<br>"; } echo '<img src="'.$image_dir.'">'; ?>
Comments
Post a Comment