Jump to content

Need help sending php variables to script


swincher4391

Recommended Posts

Here are the project of files: So the problem I'm running into is, while php ---> php is fine (it's recovering all of my variables, I've tested with echo), the problem seems to be where I have made a command  ./createlisting.sh $itemno $title $header $description $image It reads in $itemno, $title, $header $description just fine, but it fails when I try to send an image. Again I've echoed it out and my $image variable contains the correct image name. When it gets sent to the bash script and the bash script sends it to a "log.txt" it only shows $1 thru $4, excluding the $5. When I try to use the img src to create the image on the page, the outputting echo on the page is  <img src ="/images/" /> Which of course is going to result in nothing.

 

What advice can you guys offer me?

 

Thanks!

 

createPage.php:

 

<html>

<body>

<form enctype="multipart/form-data" action="submitForm.php" method="post">

Item#: <input type="text" name="itemno" value="1" /><br />

Title: <input type="text" name="title" value="My Listing" /><br />

Header: <input type="text" name="header" value="ENTER YOUR LISTING" /><br />

<textarea name="description" cols="60" rows="20">

You will have to use quotes on anything that has more than one word. Sorry!

</textarea><br><br /></p>

<input type="hidden" name="MAX_FILE_SIZE" value="100000" />

Choose an image to upload: <input name="uploadedfile" type="file" /><br />

<input type="submit" value="Submit" />

</form>

</body>

</html>

 

 

 

submitForm.php:

<?php

$itemno =  $_POST["itemno"];

$title =  $_POST["title"];

$header = $_POST["header"];

$description = $_POST["description"];

// Where the file is going to be placed

$target_path = "/home/images/";

 

/* Add the original filename to our target path. 

Result is "uploads/filename.extension" */

$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);

$image =  basename( $_FILES['uploadedfile']['name']);

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {

    echo "The file ".  basename( $_FILES['uploadedfile']['name']).

    " has been uploaded";

} else{

    echo "There was an error uploading the file, please try again!";

}

$command = "." . "/" . "createlisting.sh";

$param = $itemno . " " . $title . " " . $header . " " . $description;

$finalimage = $image . "";

$final = $command . " " . $param . " " . $finalimage;

passthru($final);

 

createlisting.sh:

 

#!/bin/bash

 

#Create the page based on the information

cd logs   

echo $1 > log.txt

echo $2 >> log.txt

echo $3 >> log.txt

echo $4 >> log.txt

        echo $5 >> log.txt

cd ..

./createNewDir.sh $(date +%m%d%Y)

cd ..

cd listings

cd $(date +%m%d%Y)

mkdir $1

cd $1

echo "<HTML>" > listing.html

echo "<Head>" >> listing.html

echo "<Title>" >> listing.html

echo "$2" >> listing.html

echo "</title>" >> listing.html

echo "</head>" >> listing.html

echo "<body>" >> listing.html

echo "<h1>$3</h1><br>" >> listing.html

        echo "<img src=\"/images/$5\" />"

echo "$4" >> listing.html

echo "</body>" >> listing.html

echo "</html>" >> listing.html

cd ..

cd ..

cd ..

cd scripts

        echo $(date +%d%m%Y);

 

 

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.