Error: <?php echo variable in string

Discuss coding issues, and scripts related to PHP and MySQL.
User avatar
JanMolendijk
Posts: 282
Location: Holland Rotterdam

Error: <?php echo variable in string

I`m buissy with an simple upload script, every member have a own folder for pictures on my server.
Now i try to add a echo variable but getting a error:

Code: Select all

Warning: move_uploaded_file(/images/<?php echo $users[email];?>/689886.jpg): failed to open stream: No such file or directory in C:\xampp\htdocs\Comments\addnew.php on line 67
I have a part of my script in code

Code: Select all

<?php
    $url = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
?>
<?php 
  
include('connection.php');

$id = (int) $_GET['id'];

$sql=mysqli_query($conn,"SELECT * FROM `user` WHERE id='" . $id . "' ");
$users=mysqli_fetch_assoc($sql);
?>


<?php echo $users['email'];?>


<?php

	error_reporting( ~E_NOTICE ); // avoid notice
	
	require_once 'dbconfig.php';
	
	if(isset($_POST['btnsave']))
	{
		$username = $_POST['user_name'];// user name
		$userjob = $_POST['user_job'];// user email
		
		$imgFile = $_FILES['user_image']['name'];
		$tmp_dir = $_FILES['user_image']['tmp_name'];
		$imgSize = $_FILES['user_image']['size'];
		
		
		if(empty($username)){
			$errMSG = "Please Enter Username.";
		}
		else if(empty($userjob)){
			$errMSG = "Please Enter Your Job Work.";
		}
		else if(empty($imgFile)){
			$errMSG = "Please Select Image File.";
		}
		else
		{
			$upload_dir = '/images/<?php echo $users[email];?>/'; // upload directory
	
			$imgExt = strtolower(pathinfo($imgFile,PATHINFO_EXTENSION)); // get image extension
		
is their an different variable for: <?php echo $users[email];?>
- or how can i make it work into $upload_dir ?

Admin Posts: 805
Hello,
Not add <?php echo ; in the value of a variable; just concatenate with dot '.':

Code: Select all

$upload_dir ='/images/'. $users['email'] .'/';

JanMolendijk Posts: 282
Thanks it is working now if you wanna have a little donation how can i ?

Admin Posts: 805
Thanks for your intention, but I not need donation.
I'm thankful with my peace.

Similar Topics