Jump to content

form create new page


searls03

Recommended Posts

You mean something like this?

 

<?php
$template  = 'templates/pictures.php';
$picture = 'lolcat.png'; //this could be the uploaded picture

//we need just the filename - no extension
$picture_name = pathinfo($picture, PATHINFO_FILENAME);

copy($template, "templates/$picture_name.php");
?>

ok I can explain what he wants

he wants to upload image from a form

then let's say the image name is 123.jpg

he wants to make page names 123.php immediately(automatic)

how can he do that?????????????? 

Thank God you arrived!!!  Without searl's translator I don't think we would ever understand.

You mean something like this?

 

<?php
$template  = 'templates/pictures.php';
$picture = 'lolcat.png'; //this could be the uploaded picture

//we need just the filename - no extension
$picture_name = pathinfo($picture, PATHINFO_FILENAME);

copy($template, "templates/$picture_name.php");
?>

 

 

Instead of potentially creating hundreds of PHP files that essentially do the same thing, wouldn't it be better to store all the picture references in a database? Then just use templates/pictures.php page to display them all based on a id. That way if the initial template ever changes, you would only need to modify one file.

so now I have it working....

<?php
$template  = 'Templates/index.php';
$picture = 'lolcat.png'; //this could be the uploaded picture

//we need just the filename - no extension
$picture_name = pathinfo($picture, PATHINFO_FILENAME);

copy($template, "$picture_name.php");
?>

 

how can I make it so that I can post certain pictures with this page that will show up?  I want to use a jquery object with this also.  how can I do this?  If it doesn't make sense let me know

one last question......how do I pull just the file extension from a picture name?  I want it to go where I have put 5 * at in the code.....I hope this makes sense.

 

$picture_name = pathinfo($picture, PATHINFO_FILENAME);
$sql = "INSERT INTO pictures (name, id, image,  event) 
	VALUES('$name', '$id','$image','$event')";
$rs = mysql_query($sql) or die ("Problem with the query: $sql<br>" . mysql_error());
	echo mysql_error();
}
copy($template, "$name.php");

?>
<form action="new.php" method="post" enctype="multipart/form-data"><input name="name" type="text" /><input name="id" type="hidden" value=<?php echo $id; ?> /><br />
<input name="event" type="text" /><input name="image" type="hidden" value="images/<?php echo $name; ?>*****" /><input name="submit" type="submit" value="submit" /></form>

I'm sure there's a more efficient way, but you could get the extension by exploding the filename with the dot '.'

 

<?php

$file_parts = explode('.', $image);
$temp = count($file_parts) - 1;
$ext = $file_parts[$temp];

?>

 

 

Note there are some security issues to work on before going live.

 

First you want to look into dealing with visitors who pretend to upload an image, but are actually uploading something like a PHP script and naming it "image.php.jpg" or "ScriptToDoSomethingBad.php".

 

You'll also want to use mysql_real_escape_string() before saving the image name (and other information) to the database. Otherwise someone could modify/access you're database using SQL injections.

http://php.net/manual/en/function.mysql-real-escape-string.php

I'm sure there's a more efficient way, but you could get the extension by exploding the filename with the dot '.'

 

<?php

$file_parts = explode('.', $image);
$temp = count($file_parts) - 1;
$ext = $file_parts[$temp];

?>

Or use pathinfo

$ext = pathinfo($image, PATHINFO_EXTENSION);

  • 2 weeks later...

 

 

<?php
$template  = 'templates/pictures.php';
$picture = 'lolcat.png'; //this could be the uploaded picture

//we need just the filename - no extension
$picture_name = pathinfo($picture, PATHINFO_FILENAME);

copy($template, "templates/$picture_name.php");
?>

 

can I also use this to make directories?  if so, How??????

You can use mkdir to dynamically create directories. Keep in mind that you can't just use any name for files and directories. Different filesystems have specific rules on file/folder names and you have to clear those characters out. Here is a round-up on different systems (just a random google search).

so like this?

<?php
include_once "secure/connect_to_mysql.php";




$uploaddir = 'images/';
$id= $_GET['id'];
$event= $_GET['name123'] = str_replace(".", " ", trim($_GET['name123']));
$site = $_GET['site'].".php";
$template  = 'template.php';
$basic  = 'basic.php';
$standard  = 'standard.php';
$picture = '$event.png';
$target_path = "images/";

$file = $uploaddir . basename($_FILES['uploadfile']['name']); 
$size=$_FILES['uploadfile']['size'];
if($size>999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999)
{
echo "error file size > 1 MB";
unlink($_FILES['uploadfile']['tmp_name']);
exit;
}
if (move_uploaded_file($_FILES['uploadfile']['tmp_name'], $file)) { 
  echo "success";
  $sql = "INSERT INTO pictures(image, name, id, event, site) 
	VALUES('$file', '$file', '$id', '$event', '$site')";
$rs = mysql_query($sql) or die ("Problem with the query: $sql<br>" . mysql_error());
	echo mysql_error();

} else {
echo "error ".$_FILES['uploadfile']['error']." --- ".$_FILES['uploadfile']['tmp_name']." %%% ".$file."($size)";

$picture_name = pathinfo($picture, PATHINFO_FILENAME);


}
copy($template, "$site");
copy($basic, "basic$site");
copy($standard, "standard$site");
mkdir("/events/$event", 0700);


?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.