Answers for "save php as image"

PHP
2

php image upload write to server

<?php error_reporting(0);

$msg = "";

if ( isset( $_POST['upload']) ) {

	$filename = $_FILES["uploadfile"]["name"];
	$tempname = $_FILES["uploadfile"]["tmp_name"];
    $folder   = $filename;

    if ( move_uploaded_file( $tempname, $folder ) ) {
        $msg = "Image uploaded successfully";
    } else{
        $msg = "Failed to upload image";
	}
}
?>

<!DOCTYPE html>
<html>
    <head>
    <title>Image Upload</title>
    </head>
    <body>

    <h2><?php echo $msg; ?></h2>
    <form method="POST" action="" enctype="multipart/form-data">
        <input type="file" name="uploadfile"/>
        <button type="submit" name="upload">UPLOAD</button>
    </form>
    </body>
</html>
Posted by: Guest on June-17-2021
0

php save image from url to folder

You should be able to use file_get_contents for this one. In order to use an URL with file_get_contents make sure allow_url_fopen is enabled in you php.ini file.

define('DIRECTORY', '/home/user/uploads');

$content = file_get_contents('http://anothersite/images/goods.jpg');
file_put_contents(DIRECTORY . '/image.jpg', $content);
Make sure that you have write permission to the directory where you want to store the image; to make the folder writable you could do this:

chmod +w /home/users/uploads
Posted by: Guest on March-11-2021

Browse Popular Code Answers by Language